What's the pattern evaluation on Jenkinsfile when-branch setting?

后端 未结 1 2100
终归单人心
终归单人心 2021-02-20 18:35

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 { b         


        
相关标签:
1条回答
  • 2021-02-20 18:44

    Ok ! So, through the error stack trace I found out that on the when-branch option, Jenkins compares with Ant style patterns: https://ant.apache.org/manual/dirtasks.html

    That means it doesn't expect regexp, but simpler stuff like:

            */staging/*
    

    I solved this by using the when-expression option instead, like this:

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

    That uses groovy expressions as described here:

    https://www.regular-expressions.info/groovy.html

    Especially, look for the explanation of the ==~ operator, that was helpful.

    For the regular expression itself, you can test yours here:

    https://regexr.com/

    0 讨论(0)
提交回复
热议问题