Jenkins Pipeline 限制其他作业

标签 jenkins groovy jenkins-workflow

我试图在 Jenkins 管道运行时锁定其他一些作业的运行,
我一直在尝试使用 exclusion-pluginthrottle-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/

相关文章:

linux - 如何在 awk 中使用 cat 命令

jenkins - 从 FreeStyle 作业执行共享库

jenkins - 如何向 Jenkins 多分支管道添加构建参数?

android - 在服务器上构建(不开发)您的Android应用.apk(渐变构建)?

linux - 如何在 Ubuntu 12.04 中更改 Jenkins 安装的端口号

Jenkins 墙展示 404

unit-testing - grails在单元测试中使用get()时,命名查询给出null

grails - 如何使用gsp模板创建文本文件?

Jenkins Build Pipeline fileLoad 在库文件中不起作用

Jenkins 管道阶段 View 添加描述