Pac*_*ace 5 jenkins jenkins-pipeline
我希望我的Jenkins multibranch管道工作能够避免触发自身.该作业进行提交,因为它会增加版本文件并将其检入源控件,从而导致无限循环.
在常规工作中,我可以按照这些说明来避免这种循环(虽然这不是最干净的方式).
这些指令不适用于多分支管道(没有"忽略某些用户的提交"选项).Jenkins mulitbranch管道中是否有任何方法可以防止自触发提交?
如果使用GIT,一种解决方法:
更改版本并提交时,请在提交日志中使用特定的消息,例如:[git-version-bump]-更改版本
在scm签出之后,检查最后一次提交是否是版本凹凸提交,如果是,则中止该作业。
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
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2933 次 |
| 最近记录: |