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

Jenkins多分支Pipeline的PathRestriction触发失效问题排查

Troubleshooting Unwanted Triggers for build-base-docker Multibranch Pipeline

Hey there, let's break down why your build-base-docker pipeline is still triggering when you modify Java files, and whether JENKINS-36195 is to blame.

First: Your Current Configuration Targets Checkout, Not Triggering

The biggest issue here is a common misunderstanding: the PathRestriction you added in your pipeline script only controls what code gets checked out during the build, not which changes trigger the pipeline in the first place.

Jenkins multibranch pipelines rely on the SCM scanner (configured in your pipeline's branch source settings) to decide when to trigger a build for a branch. This scanner checks all changes across the repository and uses path filters set in the pipeline configuration—not in the checkout step of your script—to determine if a build should run.

Your current code snippet only restricts which files are pulled during the build:

node('java-build') { 
  stage ('git checkout') { 
    checkout([ 
      $class: 'GitSCM', 
      branches: scm.branches, 
      extensions: scm.extensions + [ 
        [$class: 'PathRestriction', excludedRegions: '.*', includedRegions: 'docker/.*'] 
      ], 
      userRemoteConfigs: [[credentialsId: 'our-git-repo-deploy-key', url: 'git@github.com:we/our-repo.git']] 
    ]) 
  } 
  ... 
}

This won't stop the scanner from detecting changes to src/main/java/foo.java and triggering a build anyway.

How to Correctly Configure Path-Based Triggering

To make build-base-docker only trigger on changes to the docker/ directory, you need to set up path filtering directly in the pipeline's branch source configuration:

  • Go to your build-base-docker multibranch pipeline configuration page
  • Navigate to the Branch Source section (usually under "Branch Sources" for Git)
  • Expand the Behaviors list (labeled "Advanced clone behaviors" in older Jenkins versions)
  • Click Add and select Filter by path
  • Set the Include field to docker/** (this tells Jenkins to only care about changes under this directory)
  • Save the configuration

With this setup, the SCM scanner will only trigger a build for a branch if pushed changes modify files in docker/.

Is JENKINS-36195 Involved?

JENKINS-36195 is a historical bug that caused path filtering to fail in specific multibranch pipeline scenarios (like when using merge behaviors or certain branch naming patterns). However, this bug has been fixed in recent stable versions of the Git plugin and Pipeline Multibranch plugin.

Before assuming the bug is the cause:

  1. First implement the branch source path filtering as described above
  2. Test by pushing a change to a Java file—build-base-docker should not trigger
  3. If it still triggers, check if you're running outdated versions of Jenkins, Git plugin, or Pipeline Multibranch plugin. Upgrade to the latest stable versions and test again.

Only after confirming the correct configuration is in place and plugins are up to date should you consider residual issues from JENKINS-36195 (though this is unlikely in modern Jenkins setups).

内容的提问来源于stack exchange,提问作者Peter Kahn

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.28 09:03:53