jmr*_*cha 29 concurrency groovy jenkins jenkins-pipeline
我正在考虑在Jenkins中将并发构建的数量限制为特定的数量,利用多分支管道工作流程,但在docs或google中找不到任何好的方法.
有些文档说这可以在stageJenkins文件的步骤中使用并发来完成,但我也在其他地方读过,这是一种不赞成使用它的方式.
看起来最近发布了一些用于限制并发性的东西,Job Properties但我找不到它的文档,而且我在跟踪代码时遇到了麻烦.我发现PR的唯一一件事就是:
properties([concurrentBuilds(false)])
但是我无法让它正常工作.
有没有人知道或有一个很好的例子来说明如何限制给定的多分支项目的并发构建数量?也许是一个Jenkinsfile片段,展示了如何限制或限制多分支并发构建的数量?
jmr*_*cha 49
找到了我想要的东西.您可以使用Jenkinsfile中的以下块来限制并发构建.
node {
// This limits build concurrency to 1 per branch
properties([disableConcurrentBuilds()])
//do stuff
...
}
Run Code Online (Sandbox Code Playgroud)
使用声明性语法可以实现相同的目的:
pipeline {
options {
disableConcurrentBuilds()
}
}
Run Code Online (Sandbox Code Playgroud)
使用Lockable Resources插件 ( GitHub )可以限制并发构建或阶段。我总是使用这种机制来确保不会同时执行发布/发布步骤,而可以同时构建正常阶段。
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'
Run Code Online (Sandbox Code Playgroud)
正如@VadminKotov 指出的那样,也可以使用 jenkins 声明性管道禁用并发构建:
pipeline {
agent any
options { disableConcurrentBuilds() }
stages {
stage('Build') {
steps {
echo 'Hello Jenkins Declarative Pipeline'
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
19330 次 |
| 最近记录: |