我试图在 Jenkins 管道运行时锁定其他一些作业的运行,
我一直在尝试使用 exclusion-plugin 或 throttle-concurrent-builds-plugin
具有这种结构:
node(){
stage "test"
allocate('test')
sleep time: 15, unit: 'MINUTES'
sh "echo 'yes'" }
@NonCPS
def allocate(String resource){
throttle = new hudson.plugins.throttleconcurrents.ThrottleJobProperty(
maxConcurrentPerNode=1,
maxConcurrentTotal=1,
categories = [resource],
throttleEnabled=true,
throttleOption="category",
matrixOptions=null
)
throttle.setOwner()
throttle = null
return true
}
但它似乎没有做任何事情......
我从 Groovy Pipeline 插件开始,但由于无法限制其他作业而受阻
谢谢您的帮助!
最佳答案
对于那些处于同样奋斗中的人,
您可以使用这个插件:https://github.com/jenkinsci/lockable-resources-plugin
使用此分支:https://github.com/jenkinsci/lockable-resources-plugin/pull/25
我不知道有一天是否会合并,但 MR 完全可用,可以像这样使用:
echo 'Starting'
lock('my-resource-name') {
echo 'Do something here that requires unique access to the resource'
// any other build will wait until the one locking the resource leaves this block
}
echo 'Finish'
关于Jenkins Pipeline 限制其他作业,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36006680/