如何让 Jenkins/Hudson 工作监视其他一些工作并决定是否建立? [英] How to make a Jenkins/Hudson job surveil some others jobs and decide whether to build or not?
问题描述
问题
鉴于所有工作的工作名称中都有字符串 LEVEL_X
,其中 X 是一个 > 1 的数字.我希望 X = n 的每个工作都监视 X = n 的每个工作-1
,如果每个都成功完成,则开始构建.我希望 X = n
的作业以 1 分钟的间隔监视其他作业.
Given that all the jobs have string LEVEL_X
in it's job name, where X is a number > 1. I want every job with X = n to surveil every job with X = n-1
, and start building if each of them is finished with success. And I want the job with X = n
to surveil the other jobs with an interval of 1 minute.
首先,我想知道最好的方法是什么,其次我想要解决方案,如果可以通过一个小脚本来实现,也许是一个可以在 system groovy 中运行的 groovy 脚本脚本
使用 GROOVY 插件.
First of all, I am interested in knowing what the best way is to do that, second I want the solution if one can be implemented by a small script, maybe a groovy script which can be run in system groovy script
using the GROOVY PLUGIN.
推荐答案
以下是一些提示和代码片段:
Here are some hints and code snippets:
http://<jenkins-server>/script
有一个 Groovy 脚本控制台,可帮助您调试脚本.- 这是 Jenkins Java API 的链接.
输出所有作业名称的代码片段:
- There is a Groovy Script console at
http://<jenkins-server>/script
that will help you with debugging your scripts. - Here is a link to Jenkins Java API.
Code snippet that outputs all job names:
def hi = hudson.model.Hudson.instance
hi.getItems(hudson.model.Project).each {project ->
println(project.displayName)
}
从 LEVEL_n
中提取 n
的代码片段(实现为闭包):
Code snippet that extracts n
from LEVEL_n
(implemented as closure):
def level = { name ->
def ret = 0
name.eachMatch(~'LEVEL_([1-9]+[0-9*])', {ret = it[1].toInteger()})
return ret
}
获取所有最新版本状态的代码片段:
Code snippet that gets statuses for all the latest builds:
def hi = hudson.model.Hudson.instance
hi.getItems(hudson.model.Project).each {project ->
println(project.lastBuild.result)
}
链接到 启动一个构建.
注意:如果您使用 Matrix 构建,事情会变得有点棘手.但只要你不这样做就足够了.
Note: things get a bit hairier if you are using Matrix builds. But as long as you don't this should be enough.
这篇关于如何让 Jenkins/Hudson 工作监视其他一些工作并决定是否建立?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!