简体   繁体   English

詹金斯“执行Shell脚本”变量需要在后期构建操作中专门用于发送电子邮件正文?

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

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. 所以我在Execute Shell Script构建动作中设置了一些变量,我想在我的构建后动作中使用它,比如发送电子邮件的正文。 Is this possible without using any plugins? 这可能不使用任何插件吗? If not possible without plugins what are the plugins that I should use? 如果没有插件不可能,我应该使用哪些插件? Thanks very much, 非常感谢,

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. 执行Shell脚本后构建操作在单独的环境会话中运行,因此在前者中设置的任何内容在后者中都不可用。

What you need is the EnvInject plugin . 你需要的是EnvInject插件

  • In your Execute Shell Script step, instead of setting an environment variable, write the key-value pair to file, for example myvar=somevalue . 在“ 执行Shell脚本”步骤中,不是设置环境变量,而是将键值对写入文件,例如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). 现在,该变量可用作其余作业运行的环境变量(包括其他构建步骤和构建后步骤)。

You can set any environment variable using the " Generate environment variables from script" by using: echo "MY_VAR=$SOME_VAR" 您可以使用以下命令设置任何环境变量:“使用脚本生成环境变量” :echo“MY_VAR = $ SOME_VAR”

Then this variable is available through the entire jenkins job process. 然后,通过整个jenkins作业流程可以使用此变量。 at any shell/ batch command and even at the mail or any other plugin. 在任何shell / batch命令,甚至在邮件或任何其他插件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM