简体   繁体   English

为每个参数触发Jenkins Job

[英]Trigger Jenkins Job for every parameter

I have created a Global choice Parameter using Extensible Choice Parameter plugin. 我已经使用可扩展选择参数插件创建了一个全局选择参数

I am using this parameter list in one of my parametrized jenkins job. 我在我的参数化詹金斯工作之一中使用了此参数列表。

Is there a way in jenkins, where I can execute the job with each of the parameters in the Global choice Parameter list? 在詹金斯中,有什么方法可以使用“全局选择参数”列表中的每个参数执行作业?

I have had a look on Build Flow job in jenkins, as suggested in this answer, but it seems it accepts hardcoded parameters only, and not dynamic. 我已经按照答案中的建议看过jenkins中的Build Flow作业,但似乎它只接受硬编码的参数,而不是动态的。

I finally managed to resolve this using the following steps (with great help from this post) - 我终于设法通过以下步骤解决了这个问题(在这篇文章的大力帮助下)-

As my parameters list is dynamic in nature, it could be added or modified according to other jobs, we have managed it in a text file. 由于我的参数列表本质上是动态的,因此可以根据其他作业添加或修改它,我们已经在文本文件中对其进行了管理。

Next, We have used Extensible Choice Parameter plugin to display the parameters, using the groovy script - 接下来,我们已使用groovy脚本使用了Extensible Choice Parameter插件来显示参数-

def list = [];
File file = new File("D:/JenkinJob/parameterList.txt")

file.eachLine { line ->
  list.add("$line")
}
return list

在此处输入图片说明

Now I want to call this jenkins job for each of the parameter. 现在,我想为每个参数调用此詹金斯作业。 For this, I have installed, BuildFlow plugin, and crated a new jenkins job of BuildFlow type - 为此,我安装了BuildFlow插件,并创建了一个BuildFlow类型的新jenkins作业- 在此处输入图片说明

Next, get the Extended Choice Parameter plugin, and configure it as follows - 接下来,获取扩展选择参数插件,并按如下所示进行配置- 在此处输入图片说明

Now in the flow step of this job, write this script, where "Feature" is the parameter, that is just created above, and within call to "build" parameter, pass in the name of job which we want to call for each parameter - 现在,在此作业的流程步骤中,编写此脚本,其中“功能”是刚刚在上面创建的参数,并在对“ build”参数的调用内,传递我们要为每个参数调用的作业的名称--

def features = params['Features'].split(',')

for (feature in features ) {
    build("JobYouWantToCall", JobParameter: feature,)
}

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

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