预发送脚本如何检索参数化的Jenkins作业的参数? [英] How can a pre-send script retrieve parameters of a parameterized Jenkins job?
问题描述
我想基于参数化作业的布尔参数值取消电子邮件发送.该参数名为"skip.email".
I would like to cancel email sending based on the value of a boolean parameter of a parameterized job. The parameter is named "skip.email".
我试图编写一个包含以下内容的预发送脚本,但是它不起作用:
I tried to write a pre-send script with following content but it doesn't work :
def env = System.getenv()
logger.println("Should I skip email ? " + env['skip.email'])
cancel = env['skip.email']
这是我在日志中看到的内容:
Here is what I see in the logs :
Should I skip email ? null
我试图打印所有环境变量,但是列表中没有我的参数化Jenkins作业的任何参数.
I tried to print out all environment variables, but none of the parameters of my parameterized Jenkins job are in the list.
请帮帮我,谢谢!!
推荐答案
预发送脚本提供了一个名为"build"的变量,该变量的类型继承自 getBuildVariables 方法检索包含以下内容的地图参数化的变量.
The pre-send script provides a variable named "build", which is of a type that inherits from AbstractBuild. Use the getBuildVariables method to retrieve a Map that includes the parameterized variables.
我有一个名为"target"的参数化变量,用于描述部署环境.我希望仅在目标环境是质量检查环境的情况下才将电子邮件发送给质量检查.
I have a parameterized variable named "target" that describes a deployment environment. I want emails to only be sent to QA if the target environment was QA's environment.
if (!build.getBuildVariables().get("target").equals("qa")) {
// cancel variable cancels the email send when set to true
cancel = true
}
这篇关于预发送脚本如何检索参数化的Jenkins作业的参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!