如何限制Jenkins并发多分支管道构建? [英] How to limit Jenkins concurrent multibranch pipeline builds?

查看:1243
本文介绍了如何限制Jenkins并发多分支管道构建?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在考虑将并发构建的数量限制在Jenkins中的特定数量,利用多分支管道工作流程,但尚未找到在文档或Google中执行此操作的好方法。



有些文档说这可以在Jenkinsfile的 stage 步骤中使用并发来完成,但我也阅读其他地方,这是一种不赞成使用的方式。



看起来好像最近刚刚发布了东西,用于限制并发通过作业属性但我无法找到它的文档,我无法遵循代码。我找到了一个公关,其中显示了以下内容:



properties([concurrentBuilds(false)])



但我有麻烦得到它的工作。



有谁知道或有一个很好的例子来说明如何限制一个给定的多分支项目的并发构建数量?也许是一个Jenkinsfile代码片断,它展示了如何限制或限制多分支并发构建的数量?解析方案

找到我正在寻找的东西。您可以使用Jenkinsfile中的以下块来限制并发构建。

  node {
//这限制了构建并发到每个分支
属性([disableConcurrentBuilds()])

//做东西
...
}



使用声明性语法可以实现同样的效果:

  pipeline {
options {
disableConcurrentBuilds()
}
}


I am looking at limiting the number of concurrent builds to a specific number in Jenkins, leveraging the multibranch pipeline workflow but haven't found any good way to do this in the docs or google.

Some docs say this can be accomplished using concurrency in the stage step of a Jenkinsfile but I've also read elsewhere that that is a deprecated way of doing it.

It looks like there was something released fairly recently for limiting concurrency via Job Properties but I couldn't find documentation for it and I'm having trouble following the code. The only thing I found a PR that shows the following:

properties([concurrentBuilds(false)])

But I am having trouble getting it working.

Does anybody know or have a good example of how to limit the number of concurrent builds for a given, multibranch project? Maybe a Jenkinsfile snippet that shows how to limit or cap the number of multibranch concurrent builds?

解决方案

Found what I was looking for. You can limit the concurrent builds using the following block in your Jenkinsfile.

node {
  // This limits build concurrency to 1 per branch
  properties([disableConcurrentBuilds()])

  //do stuff
  ...
}

The same can be achieved with a declarative syntax:

pipeline {
    options {
        disableConcurrentBuilds()
    }
}

这篇关于如何限制Jenkins并发多分支管道构建?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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