Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
in DevOps and Agile by (29.3k points)

I am trying to detect the branch pattern on a when statement inside a stage.

Like this:

stage('deploy to staging') {

agent label:'some-node'

when { branch "feature/*" }

steps {

    sh './'



What if I want a more complicated pattern?

I am trying to detect something like feature/0.10.25 and the following pattern doesn't work:

when { branch 'feature/[0-9]+.[0-9]+.[0-9]+' }

It doesn't work. And it's a correct regexp, according to

1 Answer

0 votes
by (50.2k points)

With that branch option, Jenkins compares with ant style patterns so 


 Which clearly says that it doesn’t expect the regexp, but it can be done with 


To resolve this issue use when-expression option

 when { 

            expression { BRANCH_NAME ==~ /feature\/[0-9]+\.[0-9]+\.[0-9]+/ }


That uses the Groovy expression


Browse Categories