Jenkins Pipeline节流阀其他工作 [英] Jenkins Pipeline throttle other jobs

查看:107
本文介绍了Jenkins Pipeline节流阀其他工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在詹金斯管道运行时锁定其他一些作业,使其无法运行,
我一直在尝试使用排除插件 throttle-concurrent-builds-plugin
具有这种结构:

I'm trying to lock some other jobs from runing when a jenkins pipeline is running,
I've been trying to use the exclusion-plugin or the throttle-concurrent-builds-plugin
with this kind of structure :

 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插件开始,但由于无法限制其他工作而受到阻碍
谢谢您的帮助!

But it doesn't seems to do anything...
I'm starting with the Groovy Pipeline plugin, and I'm block by the inability to throttle other jobs
Thank You for your help !

推荐答案

对于那些在同一斗争中的人,
您可以使用以下插件: https://github.com/jenkinsci/lockable-resources-plugin
使用此分支: https://github.com/jenkinsci/lockable-resources-plugin /pull/25

For those who are in the same struggle,
You can use this plugin : https://github.com/jenkinsci/lockable-resources-plugin
using this branch : https://github.com/jenkinsci/lockable-resources-plugin/pull/25

我不知道是否有一天会合并,但是MR完全可用,可以像这样使用:

I Don't know if this will be merged some day, but the MR is fully usable and can be used like :

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节流阀其他工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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