0

I am trying to concatenate a file name by appending strings and the build number within the steps script in my Jenkinsfile and then pass it to create a zipFile, but the environment build number does not get recognized in the concatenated string. What is the correct syntax?

stage ('Publish Reports') {
   steps {
      script {
         def fileName = "reportFiles/" + '${env.BUILD_NUMBER}' + ".zip"
         zip zipFile: fileName, archive: false, dir: 'target/site/main' 
      }
   }
}

With this syntax, the fileName gets saved as:

reportFiles/${env.BUILD_NUMBER}.zip,

instead of the actual build number, for example :

reportFiles/1.zip
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
kokodee
  • 285
  • 1
  • 3
  • 15

1 Answers1

0

Actually, i found a resolution of the issue, it was a silly syntax error. The correct declaration was:

    def fileName = "reportFiles/${env.BUILD_NUMBER}.zip"
kokodee
  • 285
  • 1
  • 3
  • 15
  • What's the difference of strings within single or double quotes in groovy? https://stackoverflow.com/questions/6761498/whats-the-difference-of-strings-within-single-or-double-quotes-in-groovy – hakamairi Jul 23 '19 at 10:51