'Git Exclude Region in Multibranch Pipeline Job Not working

I have a GitHub repository and a multi-branch pipeline job. I am trying to exclude some paths from triggering builds, but can't get it to work. Any help would be appreciated. Here are the details.

GitHub URL: https://github.com/my-org/project-name.git

The project has App, DB and Config. DB and Config folders are inside the App. App is at the root level. There are 3 multibranch jobs and 3 Jenkinsfile at the following paths.

project-name/Jenkinsfile
project-name/db/Jenkinsfile
project-name/config/Jenkinsfile

Requirement is to ensure that a change in a file inside DB directory shouldn't trigger a build for App. PFB the checkout step in the App Jenkinsfile.

checkout([
                $class: 'GitSCM',
                branches: [[name: "*/${BRANCH_NAME}"]],
                doGenerateSubmoduleConfigurations: false,
                extensions: [[$class: 'DisableRemotePoll'],[$class: 'PathRestriction', excludedRegions: 'project-name/db/.*', includedRegions: ''],
                    [$class: 'RelativeTargetDirectory', relativeTargetDir: "my-folder-path"]
                ],
                gitTool: "my-git-portable",
                submoduleCfg: [],
                userRemoteConfigs: [
                    [
                        credentialsId: "my-creds",
                        url: "https://github.com/my-org/project-name.git"
                    ]
                ]
            ])

I have tried various combinations for excludedRegions like below. I tried generating the above syntax using the Pipeline Syntax with the option "Polling ignores commits in certain paths"

  1. project-name/db/.*
  2. project-name/db/**/*
  3. db/.*
  4. db/**/*
  5. With and without "includedRegions"
  6. With and without DisableRemotePoll (Force Polling using Workspace)

None of the above seems to be working. Can anyone please help me with this?



Solution 1:[1]

I know the question is a bit old, but in case anyone faces this issue here's the solution I was able to find.

Using the PathRestriction plugin seems not to work in multibranch pipelines but the multibranch-build-strategy-extension does the same work.

I found the plugin in a comment for the ticket JENKINS-35988

DISCLAIMER: The plugin's latest release was 3 years ago at the time of writing, use at your own risk

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 lucasgiaco