使用 groovy 变量触发参数化构建
trigger parameterized build with groovy variable
我有一个 Jenkins Freestyle 作业,在构建区域中有一个系统 groovy 脚本。执行脚本后,我想触发管道作业。管道作业需要一个在我的 groovy scipt.
中定义的变量
if(condition1){
var = 'String1'
}else{
var = 'String2'
}
但我需要在 "Trigger parameterized build on other projects" 选项的 "post-build-action" 步骤访问我的变量 var
以使用 var
作为参数触发我的管道。这可能吗?
是的,这是可能的。您可以简单地将变量作为键值对写入 属性 文件中,然后通过指定 Parameters from properties file
.
将其加载到 post-build-action 中
您可以像这样保存 属性 文件
def fw = new OutputStreamWriter(new FileOutputStream("params.properties",true), 'UTF-8')
def props = new Properties()
props.setProperty('TESTPARAM', var)
props.store(fileWriter, null)
fw.close()
我通过以下方式解决了我的问题:
在构建之前,我定义了一个参数来使用参数化触发器插件。在我的系统 groovy 脚本中,我用
覆盖了它
def newMailParameter = new StringParameterValue('MAIL_PARAM', mailsFromWS)
build.replaceAction(new ParametersAction(newMailParameter))
现在我可以触发下一个作业并在其中使用我的参数 MAIL_PARAM
。
我有一个 Jenkins Freestyle 作业,在构建区域中有一个系统 groovy 脚本。执行脚本后,我想触发管道作业。管道作业需要一个在我的 groovy scipt.
中定义的变量if(condition1){
var = 'String1'
}else{
var = 'String2'
}
但我需要在 "Trigger parameterized build on other projects" 选项的 "post-build-action" 步骤访问我的变量 var
以使用 var
作为参数触发我的管道。这可能吗?
是的,这是可能的。您可以简单地将变量作为键值对写入 属性 文件中,然后通过指定 Parameters from properties file
.
您可以像这样保存 属性 文件
def fw = new OutputStreamWriter(new FileOutputStream("params.properties",true), 'UTF-8')
def props = new Properties()
props.setProperty('TESTPARAM', var)
props.store(fileWriter, null)
fw.close()
我通过以下方式解决了我的问题:
在构建之前,我定义了一个参数来使用参数化触发器插件。在我的系统 groovy 脚本中,我用
覆盖了它def newMailParameter = new StringParameterValue('MAIL_PARAM', mailsFromWS)
build.replaceAction(new ParametersAction(newMailParameter))
现在我可以触发下一个作业并在其中使用我的参数 MAIL_PARAM
。