我正在使用Multibranch Pipeline项目来构建我的应用程序。我们有大约100多个组件和许多管道项目。所以说对于例如我们有:
项目A
依赖于→项目B
依赖于→项目C
我们正在使用SCM轮询来完成所有这些工作。我希望在构建项目C
之后,应该构建项目B
,然后应该构建项目A
。我的依赖项列表因项目而异。
我知道Maven项目可以使用构建触发器→☑ Build来处理这个问题,只要构建了SNAPSHOT依赖项,但是使用Multibranch Pipeline插件时,没有找到任何方法处理这件事。
任何指针?
答案 0 :(得分:2)
在分支配置页面中建立其他项目之后有 Build 并且可以选择它但是分支的配置无法保存(分支侧栏中的菜单项只读查看配置,而不是配置)。
以下Jenkinsfile
应该做你想要达到的目标。将其添加到您的所有分支机构。如果有更改,请在master
/ trunk
上进行修改,然后将其编辑到受这些更改影响的分支机构。
// 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 ) : ""
}
在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
在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
请务必使用管理Jenkins 进程内脚本批准下的Script Security Plugin批准最初禁用的功能。