You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Jenkins多分支流水线Scan Multibranch Pipeline无限循环构建求助

Fixing Infinite Loop in Jenkins Multibranch Pipeline with Version Push to Git

Alright, let's break down the root cause first: your pipeline is pushing a version increment commit back to Git, which triggers the Scan Multibranch Pipeline job to detect a new change, kick off another build, and the cycle repeats endlessly. Here are the most practical solutions to stop this:

1. Add a "Skip CI" Tag to Version Commit Messages (Simplest Fix)

Jenkins automatically ignores commits that include [skip ci] or [ci skip] in their messages. Just modify your version increment commit to include this tag, and the scan won't trigger a new build for that specific push.

Example with Git CLI:

git commit -m "Increment snapshot version [skip ci]"
git push origin <your-branch>

If Using Maven's Versions Plugin:

Configure the plugin to include the skip tag in the commit message directly in your pom.xml:

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>versions-maven-plugin</artifactId>
  <version>2.16.1</version>
  <configuration>
    <commitMessage>Increment snapshot version [skip ci]</commitMessage>
    <push>true</push>
    <!-- Other plugin configurations -->
  </configuration>
</plugin>

2. Exclude Jenkins Service User from Triggering Builds

If you're using a dedicated Jenkins service account to push the version commits to Git, you can tell the Multibranch Pipeline to ignore commits from this user entirely.

Configuration Steps:

  1. Go to your Multibranch Pipeline project → Configure
  2. Under Branch Sources, expand your Git repository configuration
  3. Click Advanced to reveal more options
  4. In the Excluded users field, enter the username of your Jenkins service account (the one used to push version changes)

This way, any commits from that user won't trigger a new build scan.

3. Add Pipeline Logic to Exit Early for Version Commits

You can add a check at the start of your pipeline to detect if the current build was triggered by a version increment commit, and exit immediately if so.

Example Groovy Pipeline Code:

pipeline {
  agent any
  stages {
    stage('Check Trigger Source') {
      steps {
        script {
          // Get the latest commit message
          def latestCommitMsg = sh(
            script: 'git log --format=%B -n 1 HEAD',
            returnStdout: true
          ).trim()
          
          // Check if it's a version increment commit
          if (latestCommitMsg.contains('Increment snapshot version')) {
            echo "Build triggered by version increment commit — exiting early to avoid loop."
            currentBuild.result = 'SUCCESS'
            return // Skip remaining stages
          }
        }
      }
    }
    
    // Your regular build, test stages here...
    
    stage('Increment & Push Version') {
      steps {
        // Your version increment and Git push logic here
      }
    }
  }
}

4. Isolate Version Updates to Manual Triggers or Separate Branches

For more control, you can restrict the version increment step to only run when the build is manually triggered, or push version changes to a separate branch that doesn't trigger Multibranch scans.

Example: Run Version Step Only on Manual Triggers

pipeline {
  agent any
  stages {
    // Build and test stages run for all triggers...
    
    stage('Increment Version') {
      when {
        triggeredBy 'UserIdCause' // Only runs for manual builds
      }
      steps {
        // Version increment and push logic here
      }
    }
  }
}

My top recommendation is the first method ([skip ci] in commit messages) — it's quick, low-effort, and works with almost any setup without changing your pipeline structure or project configurations.

内容的提问来源于stack exchange,提问作者Antonio Petricca

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 09:21:12