0

I've got a Jenkins multibranch pipeline and I'm trying to filter branches and tags, but none of my filters seem to work.

I've added "Discover branches" and "Discover tags" and I can see in the logs that branches and tags are discovered, and builds scheduled.

However, I'd like to filter out certain tags, but the scan logs show every branch and tag satisfies the criteria. This is so even when I add an "Exact Name" branch filter such as "foobar":

branch name filter

Repository type: Git
Looking up **** for branches
Checking branch release/1.2.3 from ****
      ‘Jenkinsfile’ found
    Met criteria
...
Checking branch master from ****
      ‘Jenkinsfile’ found
    Met criteria

This is using Bitbucket source, but similar issue occurs with Git source.

Can anyone tell me what I am doing wrong here? I would think that none of the branches/tags in my repo would match 'foobar', but the scan log shows everything matching.

John Q Citizen
  • 321
  • 1
  • 6
  • 15

2 Answers2

0

Sorry to tell you that it didn't work for me, too. So I decided to use the Jenkinsfile and some RegEx (used regexr.com to figure out) to "Filter" my Branches.

Add the following as the first step in your stage to achieve some kind of filtering:

when { expression {env.BRANCH_NAME =~ /[RegEx Here]/}}
ecm
  • 2,583
  • 4
  • 21
  • 29
  • Thanks, I do have a filter in the Jenkinsfile, but nothing matches the tag I want to avoid, so the build fails and the commit gets a 'failed' bitbucket build status. Better to avoid invoking the Jenkinsfile in the first place, if possible. – John Q Citizen Sep 06 '21 at 21:15
0

Okay ... I figured it out.

The correct method is to add the "Filter By Name" option (under "Behaviours") rather than "Named Branches" option (under "Build Strategies").

They do seem to be kinda similar concepts, at first glance.

John Q Citizen
  • 321
  • 1
  • 6
  • 15