Can not change Jenkins String Parameter Variable

2019-01-25 12:34发布

I have Jenkins String Parameter ${EMAIL_ID} where user can enter their email id. (say they entered myid@gmai.com

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='example@ex.com'
echo $EMAIL_ID
--returns example@ex.com

If I use this variable in next Execute Shell it returns myid@gmai.com

I need to print example@ex.com

3条回答
贼婆χ
2楼-- · 2019-01-25 12:39

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.

查看更多
萌系小妹纸
3楼-- · 2019-01-25 12:41

I disagree to Slav.

it's possible to handover variables also w.o. Plugin. just do:

echo set ENV_VAR=%ENV_VAR%>env_vars.bat

and then load it in the other batch scripts with:

call env_var.bat
查看更多
叛逆
4楼-- · 2019-01-25 12:57

You should access the Jenkins environment variable like this in your batch script: %EMAIL_ID%

查看更多
登录 后发表回答