[英]How to avoid Jenkins multibranch pipeline job triggering itself
我希望我的Jenkins multibranch管道工作能够避免触发自身。 该作业进行提交,因为它会增加版本文件并将其检入源控件,从而导致无限循环。
在常规工作中,我可以按照这些说明来避免这种循环(虽然这不是最干净的方式)。
这些指令不适用于多分支管道(没有“忽略某些用户的提交”选项)。 Jenkins mulitbranch管道中是否有任何方法可以防止自触发提交?
使用GIT时的解决方法:
碰撞版本并提交时,在提交日志中使用特定消息,例如: [git-version-bump] - Bumping version
在scm checkout之后,检查最后一次提交是否是版本提交提交,如果是,则中止该作业。
stage('Checkout') {
checkout scm
if (lastCommitIsBumpCommit()) {
currentBuild.result = 'ABORTED'
error('Last commit bumped the version, aborting the build to prevent a loop.')
} else {
echo('Last commit is not a bump commit, job continues as normal.')
}
}
private boolean lastCommitIsBumpCommit() {
lastCommit = sh([script: 'git log -1', returnStdout: true])
if (lastCommit.contains("[git-version-bump]")) {
return true
} else {
return false
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.