Jenkins groovy构建步骤触发groovy脚本中的另一项工作,删除原始作业的参数 [英] Jenkins groovy build step trigger another job in groovy script removes original job's parameters

查看:409
本文介绍了Jenkins groovy构建步骤触发groovy脚本中的另一项工作,删除原始作业的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用groovy脚本来触发其他作业,这些作业基于 Groovy插件页面。



我得到作为参数的作业列表,验证它们是否存在,并用几个参数触发它们。请参阅主触发器代码:

  //准备参数数组
def params =
[
new StringParameterValue('PARAM1','val1'),
new StringParameterValue('PARAM2','val2'),
]
def future = job.scheduleBuild2(0,new Cause.UpstreamCause (build),new ParametersAction(params))
println等待完成+ jobLink
anotherBuild = future.get()

我的触发作业完美运行,但存在一个主要问题。它们的原始参数丢失,并被新的参数 PARAM1 PARAM2 所取代。如何触发a工作和添加到其默认参数和不能替换它们?



我努力寻找解决方案并没有找到一个......



编辑:我在考虑不设置参数(并允许作业使用其默认值),但为作业的执行设置环境变量。有没有人有一个想法或例子如何做到这一点?

解决方案

在尝试了很多选项后,我决定加载默认参数对于我要触发的工作,并将它们添加到我正在准备的参数数组中,如下面的示例中所示。



我使用这里来获得我的工作的初始默认配置。



我仍然需要添加一些逻辑来选择参数和空值,但我对当前的结果感到满意。



我希望这有助于。


I'm using a groovy script to trigger other jobs, which is based on the example from the Groovy plugin page.

I get a list of jobs as a parameter, validate they exist and trigger them with a few parameters. See main trigger code:

    // Prepare parameters array
    def params = 
    [
        new StringParameterValue('PARAM1', 'val1'),
        new StringParameterValue('PARAM2', 'val2'),
    ]
    def future = job.scheduleBuild2(0, new Cause.UpstreamCause(build), new ParametersAction(params))
    println "Waiting for the completion of " + jobLink
    anotherBuild = future.get()

My triggered jobs run perfectly, but with one major problem. Their original parameters are lost and are replaced by the new ones PARAM1 and PARAM2.

How to I trigger a job and add to its default parameters and not replace them?

I tried hard to find a solution for it and didn't find one...

EDIT: I was thinking of not setting parameters (and allowing job to use its defaults), but setting environment variables for the job's execution. Does anyone have an idea or example on how to do this?

解决方案

After trying many options, I decided to load the default parameters for the job I'm about to trigger and add them to the parameter array I'm preparing as in the example below.

I used the example from here to get my job's initial default configuration.

I still has to add some logic to choices parameters and null values, but I'm happy with the current result.

I hope this helps.

这篇关于Jenkins groovy构建步骤触发groovy脚本中的另一项工作,删除原始作业的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆