Jenkins Pipeline throttle other jobs

北慕城南 提交于 2021-02-07 08:42:01

问题


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
}

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 !


回答1:


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

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'



回答2:


Throttle plugin is not supported in pipeline yet - JENKINS-31801.

Locks and Latches plugin can help in some simple cases, though it might be deprecated in the future - Proposed Plugin Deprecation.



来源:https://stackoverflow.com/questions/36006680/jenkins-pipeline-throttle-other-jobs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!