Jenkins-让代理商等待其他代理商完成 [英] Jenkins - make agents wait for other agent to finish
问题描述
我是Jenkins的新手,我正在尝试建立一个项目,该项目将只使用很少的构建执行程序. 流程如下:
I'm new to Jenkins and I'm trying to setup a project which will use few build executors. The flow shall be as follows:
- 两个带有
webservice
标签的构建执行器返回其IP地址,并等待第三个构建执行器完成其工作 - 带有
tester
标签的第三个构建执行器收集这些IP地址并执行一些长期运行的工作(例如,将HTTP请求发送到部署在这两个代理上的Web服务)
- two build executors with
webservice
label return their IP addresses and wait for the third build executor to finish its job - third build executor with
tester
label collects those IP addresses and performs some long running job (e.x. sends HTTP requests to the webservices deployed on those two agents)
如何在詹金斯中实现这种行为?
How to achieve such behavior in Jenkins?
我发现,当构建执行器完成工作时,它会立即释放,我不知道如何让它等待其他构建执行器完成工作.
I've found that when an build executor finishes its job it is immediately released and I don't know how to make it wait for other build executors to finish their jobs.
修改:
我忘了提到我要保留带有webservice
标签的构建执行器(不适用于其他作业),直到带有tester
标签的构建执行器将完成其长期运行的工作.
I forgot to mention that I want the build executors with the webservice
label to be reserved (not available for other jobs) till the build executor with the tester
label will finish its long-running job.
所有这些构建执行器也应分别位于单独的从属设备上.这意味着每个从站只有一个构建执行器.
Also all these build executors should be on separate slaves each. That means each slave has only one build executor.
推荐答案
我终于设法使用 管道 及以下脚本:
I've finally managed to do this using Pipeline and below script:
node('webservice') {
def firstHostname = getHostname()
node('webservice') {
def secondHostname = getHostname()
node('tester') {
println 'Running tests against ' + firstHostname + ' and ' + secondHostname
// ...
}
}
}
def getHostname() {
sh 'hostname > output'
readFile('output').trim()
}
它获得两个带有webservice
标签的构建执行程序.我正在获取它们的主机名(我在使用它们而不是IP地址),并使用tester
标签将它们传递给构建执行器.最后,tester
运行一些长时间运行的测试.
It acquires two build executors with webservice
label. I'm getting their hostnames (I'm using them instead of the IP addresses) and pass them to the build executor with a tester
label. Finally the tester
runs some long-running tests.
这两个webservice
构建执行器被阻止,直到tester
完成其工作,并且在此期间没有其他项目可以使用它们.
Those two webservice
build executors are blocked till the tester
finishes its job, and no other project may use them during that time.
这篇关于Jenkins-让代理商等待其他代理商完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!