Created
January 18, 2018 10:21
-
-
Save tknerr/c79a514db4bdbfb4956aaf0ee53836c8 to your computer and use it in GitHub Desktop.
Example JobDSL for a multibranchPipelineJob which keeps only the last 10 builds
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// define the bitbucket project + repos we want to build | |
def bitbucket_project = 'myproj' | |
def bitbucket_repos = ['myrepo1', 'myrepo2'] | |
// create a pipeline job for each of the repos and for each feature branch. | |
for (bitbucket_repo in bitbucket_repos) | |
{ | |
multibranchPipelineJob("${bitbucket_repo}-ci") { | |
// configure the branch / PR sources | |
branchSources { | |
branchSource { | |
source { | |
bitbucket { | |
credentialsId("top-secret-1234-some-guid") | |
repoOwner("${bitbucket_project.toUpperCase()}") | |
repository("${bitbucket_repo}") | |
serverUrl("https://bitbucket.acme.com/") | |
traits { | |
headWildcardFilter { | |
includes("master release/* feature/* bugfix/*") | |
excludes("") | |
} | |
} | |
} | |
} | |
strategy { | |
defaultBranchPropertyStrategy { | |
props { | |
// keep only the last 10 builds | |
buildRetentionBranchProperty { | |
buildDiscarder { | |
logRotator { | |
daysToKeepStr("-1") | |
numToKeepStr("10") | |
artifactDaysToKeepStr("-1") | |
artifactNumToKeepStr("-1") | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
// discover Branches (workaround due to JENKINS-46202) | |
configure { | |
def traits = it / sources / data / 'jenkins.branch.BranchSource' / source / traits | |
traits << 'com.cloudbees.jenkins.plugins.bitbucket.BranchDiscoveryTrait' { | |
strategyId(3) // detect all branches | |
} | |
} | |
// check every minute for scm changes as well as new / deleted branches | |
triggers { | |
periodic(1) | |
} | |
// don't keep build jobs for deleted branches | |
orphanedItemStrategy { | |
discardOldItems { | |
numToKeep(-1) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I tried this approach but it does not work for me. It indeed will block build number n+1 even after build number n is finished.
What disableConcurrentBuilds does is that only one build at a time is running.
I was unsuccessful in trying to use it properly in job DSL 1.77. Any hint appreciated