Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can not change Jenkins String Parameter Variable

Tags:

jenkins

hudson

I have Jenkins String Parameter ${EMAIL_ID} where user can enter their email id. (say they entered [email protected]

But in the middle of the process i would like to change it to some value that i specify in the configuration as below in Execute Shell .

EMAIL_ID='[email protected]'
echo $EMAIL_ID
--returns [email protected]

If I use this variable in next Execute Shell it returns [email protected]

I need to print [email protected]

like image 603
logan Avatar asked Feb 24 '14 15:02

logan


1 Answers

Each "Execute Shell" or any other build step initiates a new and separate environment. This new environment inherits a copy of actual environment variables and all build parameters that are defined for the job, but realize that they are copies/inherited.

You can change the value of an environment variable easily:

  • param=new_value (in Unix)
  • set param=new_value (in Windows)

However that change will be local to that instance of the "execute shell" step. You can see the change if you echo that variable within the same "execute shell" step, but in the next "execute shell", you get a new copy (with original value).

To preserve your changed variable between build steps (or between jobs for that matter), you need to save it during the first step, and load it during the next. Easiest is to output the value to a file:
echo param=$param > temp.props
And then read this file into the second "execute shell" step using EnvInject plugin (note, you will need to configure EnvInject build step in between your 2 existing "execute shell" steps.

like image 117
Slav Avatar answered Oct 24 '22 13:10

Slav