MadJlzz
MadJlzz

Reputation: 886

Interpolation of variables inside Jenkinsfile

I am asking for help now because I have been struggling with a simple sed command to be called inside a Jenkinsfile that needs a little variable interpolation.

Better showing the command instead of a large explanation:

sh "sed -i -e 's/-RELEASE/-${unixEpoch}/g' myFile"

sed does not agree with this syntax and prints that the command s/ is not finished.

I have read Groovy documentation about String and GString but I still don't understand what I am doing wrong ?

Any clues on this?

EDIT:

I am getting the unixEpoch by calling date +%s in order to get the current timestamp.

I printed the command just to be sure what's executed and I found:

sed -i -e 's/-RELEASE/-1525341883'
/g' myFile

The full error sent by sed is:

sed: -e expression #1, char 22: unterminated 's' command

I found weird that the printed command has an \n in the middle of it...

Upvotes: 3

Views: 1273

Answers (1)

mkobit
mkobit

Reputation: 47269

date +%s has a newline at the end, and when you interpolate it into your generated sed it is including that newline which explains why sed is complaining. You could do ${unixEpoch.trim()} or trim the unixEpoch value before using it.

Upvotes: 2

Related Questions