How to trigger build in each change for specific branches only?

Hi all,

I have multiBranch pipeline job, that triggered in each SCM change by this definition:

triggers {
          pollSCM  '* * * * *'

I want to trigger the build in each modification in develop/master/release branch, but not in feature branch. The feature branch build will trigger manually.
I tried to remove the triggers block from the jenkins files in the feature branches, but this make issues in the branch merge to develop.
I also tried to add filter by name to the behavior section in the multiBranch pipeline configuration, but this make the build of the feature branch disabled, and I want it to be enable and not run in each modification.

Any idea?


Hello @OsFr ,

What about filtering branches with regular expressions instead of wildcards?


Hello Bruno,

Thank for your replay.
Use filtering by wildcards gives the same results as regex - the feature branch build become disabled. and I want it to be enable and not run in each modification.

1 Like

Hi All,

I found a way to do that:

In the multi branch configuration I add branch filtering (regex or wildcards). so the main branches (develop, master and release) are running in each modification.
I add to the pipeline ( in JenkinsFile) string parameter that indicate the requested branch to build. By default, this parameter = env.BRANCH_NAME.
The logic use this parameter to load the correct branch.
The user can use “build with parameter” to run build in specific branch.

Open issue:
I try to use git parameter instead of string parameter, but the git parameter is affected by the SCM configuration, which is exclude the feature branches, so feature branches doesn’t appear in the list…

If you have idea how to resolve this open issue, or you have more elegant way to do this, I would like to here!

1 Like

I’m not sure that would fit, but could yo have specific tests for branches within the Jenkinsfile?

when { not { branch 'master' } }

If I will add condition in the Jenkinsfile:

  1. The job will triggered in every change in feature branch and do nothing
  2. Who will the job run for user request on feature branch?

You’re right, my suggestions were totally off.
Let’s hope someone more knowledgeable will chime in. :pray: