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

问题描述

我正在考虑将 Jenkins 中的并发构建数量限制为特定数量,利用多分支管道工作流程,但在文档或谷歌中没有找到任何好的方法.

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.

一些文档说这可以在 Jenkinsfile 的 stage 步骤中使用并发来完成,但我也阅读别处,这是一种已被弃用的做法.

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.

看起来最近发布了一些东西,用于通过Job Properties 但我找不到它的文档,而且我在跟踪代码时遇到了问题.我发现的唯一一个 PR 显示以下内容:

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.

有没有人知道或有一个很好的例子来说明如何限制给定的多分支项目的并发构建数量?也许 Jenkinsfile 片段显示了如何限制或限制多分支并发构建的数量?

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?

推荐答案

找到了我要找的东西.您可以使用 Jenkinsfile 中的以下块来限制并发构建.

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 并发多分支管道构建?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 14:51