Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
404 views
in Technique[技术] by (71.8m points)

hudson - Can not change Jenkins String Parameter Variable

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]

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...