1

I'm trying to set a variable for a key value pairing in a jenkinsfile and can't get it to recognize the variable as a string.

zip = "name_of_zip_file_to_use"
createZipFile = [src:"./test", destination:"./"+zip+".zip"]

I have tried to use the variable zip as the whole string also but nothing seems to work. I'm not sure why it isn't recognizing the destination value variable as a string. Any ideas why I can't get this to work in the jenkinsfile?

Andrej Istomin
  • 2,527
  • 2
  • 15
  • 22
Bruce227
  • 893
  • 5
  • 14
  • 25

1 Answers1

0

Referencing and interpolating variable is possible this way - using ${VARIABLE_NAME} syntax. So in your case it would look:

zip = "name_of_zip_file_to_use"
createZipFile = [src:"./test", destination:"./${zip}.zip"]

If interested more about referencing variables and/or a string concatenation, see docs or similar StackOverflow topics:

David-kn
  • 323
  • 2
  • 8
  • Still get the error: ERROR: Please provide valid value of createZipFiles in Jenkinsfile. Aborting Build!! – Bruce227 Jan 27 '23 at 13:55
  • Could you share how does your pipeline look like? Where exactly are you using this piece of code (JSL, pipeline steps? stages? is your pipeline scripted or declarative?) otherwise it's hard to guess what might be the root cause. – David-kn Jan 27 '23 at 15:00