Jenkins “Execute Shell Script” vars needed in post-build action specifically in send email body?

匿名 (未验证) 提交于 2019-12-03 01:38:01

问题:

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.



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!