This seems too trivial to ask, but I could not find an answer:
In a Multibranch Pipeline project (controlled by Jenkinsfile): How can I skip previous builds on a branch, if there is a newer one and only build the latest commit and/or the tip of the branch?
Build is running
├────────────────────┤
o────────o────────o────────o
↑ ↑ ↑ ↑
Build Skip Skip Build this
──────────────────────────────────>
(t)
What's a Jenkins Multibranch Pipeline? A multibranch job is simply a folder of pipeline jobs. For every branch you have, Jenkins will create a folder. So instead of creating a pipeline job for each of the branches you have in a git repository, you could use a multibranch job.
Concurrent builds are enabled by default. That is why the is the disableConcurrentBuilds() function. So there is no need to add any additional code to your pipeline to enable concurrent builds.
The Multibranch Pipeline project type enables you to implement different Jenkinsfiles for different branches of the same project. In a Multibranch Pipeline project, Jenkins automatically discovers, manages and executes Pipelines for branches which contain a Jenkinsfile in source control.
Jenkins built-in workflow-job-plugin
has disableConcurrentBuilds
directive that takes one boolean
parameter named abortPrevious
. The parameter is undocumented in the official Jenkins documentation but is mentioned in the PR to the workflow-job-plugin
and available since version 2.42 of the aforementioned plugin.
Having that in mind the feature to cancel previous builds can be enabled in Jenkins by:
using Scripted Pipeline:
node {
properties([
disableConcurrentBuilds(abortPrevious: true)
])
[...]
}
using Declarative Pipeline:
pipeline {
agent any
options {
disableConcurrentBuilds(abortPrevious: true)
}
stages { ... }
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With