There is ☐ Build after other projects are built in the branches' configuration pages and it can be selected but the branches' configurations cannot be saved (The menu item in the branches' side bar reads just View Configuration, not Configure).
The following as Jenkinsfile
should do what you're trying to achieve. Add it to all of your branches. In case of changes edit it on your master
/trunk
and cherrypick it to branches that are affected by these changes.
// From: Trigger dependent jobs in Multibranch Pipeline project
// http://stackoverflow.com/a/38151703/1744774
String[][] buildChains = [
['master'],
['branch1', 'master'],
['branch2', 'branch1', 'master'],
['no-build']
// ... further build chains ...
]
for ( buildChain in buildChains ) {
if ( buildChain[0].equalsIgnoreCase( env.BRANCH_NAME ) ) {
int depth = 0
for ( branch in buildChain ) {
String depthIndicator = "+" * ++depth
//optional: String depthIndicator = new String(new char[++depth]).replace('\0', '+')
//optional: String depthIndicator = repeat( "+", ++depth )
println " $depthIndicator Triggering build for branch '$branch'"
build( branch )
} // for ( branches )
break // comment this if there are more build chains for one branch
}
} // for ( buildChains )
def build( String branch ) {
switch ( branch ) {
case "master":
buildMaster()
break
case ["branch1", "branch2"]:
buildBranch( branch )
break
// case ...
// ...
default:
println " --- No build defined for branch \'$branch\' ---"
} // switch ( branch )
} // build( branch )
def buildMaster() {
println ' Building branch \'master\'...'
// ... build code ...
}
def buildBranch( String branch ) {
println " Building branch '$branch'..."
// ... build code ...
}
// From: Can I multiply strings in Java to repeat sequences?
// http://stackoverflow.com/a/34650746/1744774
String repeat( String s, int count ) {
return count > 0 ? s + repeat( s, --count ) : ""
}
Running it on branch1
:
[Pipeline] echo
+ Triggering build for branch 'branch1'
[Pipeline] echo
Building branch 'branch1'...
[Pipeline] echo
++ Triggering build for branch 'master'
[Pipeline] echo
Building branch 'master'...
[Pipeline] End of Pipeline
Finished: SUCCESS
Running it on branch2
:
[Pipeline] echo
+ Triggering build for branch 'branch2'
[Pipeline] echo
Building branch 'branch2'...
[Pipeline] echo
++ Triggering build for branch 'branch1'
[Pipeline] echo
Building branch 'branch1'...
[Pipeline] echo
+++ Triggering build for branch 'master'
[Pipeline] echo
Building branch 'master'...
[Pipeline] End of Pipeline
Finished: SUCCESS
Remember to approve initially prohibited functions with the Script Security Plugin under Manage Jenkins → In-process Script Approval.