本文介绍了如何避免Jenkins多分支管道作业触发自身的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的Jenkins多分支管道工作避免触发自身.作业之所以提交,是因为它将递增版本文件并将其检入源代码管理,这将导致无限循环.

I would like my Jenkins multibranch pipeline job to avoid triggering itself. The job makes a commit because it increments the version file and checks it into source control which causes an endless loop.

在常规工作中,我可以关注这些说明,以避免这种循环(尽管这不是最干净的方法).

In a regular job I can follow these instructions to avoid this loop (although it's not the cleanest way).

该指令不适用于多分支管道(没有忽略某些用户的提交"选项). Jenkins多分支管道中是否有任何方法可以防止自我触发的提交?

The instructions do not work for a multibranch pipeline (there is no 'ignore commits from certain users' option). Is there any way in a Jenkins mulitbranch pipeline to prevent a self-triggered commit?

推荐答案

使用GIT时的解决方法:

A workaround if using GIT:

更改版本并提交时,请在提交日志中使用特定的消息,例如: [git-version-bump]-更改版本

When bumping the version and committing, use a specific message in the commit log eg: [git-version-bump] - Bumping the version

在scm签出后,检查最后一次提交是否是版本凹凸提交,如果是,则中止作业.

After scm checkout, check if the last commit was a version bump commit, if it is, abort the job.

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
    }
}

这篇关于如何避免Jenkins多分支管道作业触发自身的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 21:05