So I set up some vars in Execute Shell Script build action which I would like to use in my post-build action like send email's body. Is this possible without using any plugins? If not possible without plugins what are the plugins that I should use? Thanks very much,
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Not possible without plugins because:
- Execute Shell Script and Post-build actions are run in separate environment sessions, so anything that had been set in the former is not available in the latter.
What you need is the EnvInject plugin.
- In your Execute Shell Script step, instead of setting an environment variable, write the key-value pair to file, for example
myvar=somevalue
. - Add another build step, called Inject environment variables for your job. Give it the location of the file with the key-value pair.
- Now that variable is available as an environment variable for the rest of the job run (including other build steps and post-build steps).
回答2:
You can set any environment variable using the "Generate environment variables from script" by using: echo "MY_VAR=$SOME_VAR"
Then this variable is available through the entire jenkins job process. at any shell/ batch command and even at the mail or any other plugin.