how to concatenate strings in a Jenkinsfile? how to concatenate strings in a Jenkinsfile? jenkins jenkins

how to concatenate strings in a Jenkinsfile?


Does this work?

versionFromFile = readFile("./version")sh "git tag ${versionFromFile}-${env.BUILD_NUMBER}"

assuming that versionFromFile is read from the file correctly of course. To test that isn't your problem, you could just define it like this

versionFromFile = "99"sh "git tag ${versionFromFile}-${env.BUILD_NUMBER}"


Jenkinsfiles follows the same syntax as Groovy language (with some exceptions). See Jenkins syntax

The way to concatenate strings in a Jenkinsfile is using the plus character ("+"). For example:

VAR1 = "THIS IS"VAR2 = 4RESULT = VAR1 + " " + VAR2 + " " + PARAMecho "$RESULT"

Then if PARAM is an input parameter with the value "YOU" then the printed output is:

"THIS IS 4 YOU"

Then regarding your problem with environment variable ${env.BUILD_NUMBER} try to simply use BUILD_NUMBER instead.