Home > Mobile >  How to add regular expression to jenkins pipeline?
How to add regular expression to jenkins pipeline?

Time:09-09

There is a job in jenkins that is triggered by a webhook from github. I want the build steps to be triggered by matching the twig regex. It will not work to add a trigger to the expression generic webhook, because some steps must be triggered by the regular expression condition, and others by the match condition of the main branch. Can you please tell me how to set the condition for the regular expression? (Regular - refs/heads/release/\d .\d ) For example:

when { 
            environment(name: "ref", value: "refs\\/heads\\/release\\/\\d \\.\\d ")
        }

But it doesn't worked

CodePudding user response:

Please read documents carefully before asking!

There is no syntax format like "when environment". Try "when expression", for example:

stage("example") {
        when { expression { return egText.contains("abcd") } }

Beside that, about environment:

The environment directive specifies a sequence of key-value pairs which will be defined as environment variables for all steps, or stage-specific steps, depending on where the environment directive is located within the Pipeline. This directive supports a special helper method credentials() which can be used to access pre-defined Credentials by their identifier in the Jenkins environment.

We can use environment variables by using "env. ". Assume VERSION is a environment variable, we can 'touch' this variable, for example - assign value, like: "env.VERSION = "1.1a""

  • Related