content_image/763248.jpg
// Declarative // pipeline { agent any tools { maven 'apache-maven-3.0.1' ① } stages { stage('Example') { steps { sh 'mvn --version' } } } } // Script // 

① The tool name must be pre-configured in Jenkins under Manage Jenkins → Global Tool Configuration . 

## when 

The when  directive allows the Pipeline to determine whether the stage should be executed depending on the given condition. The when  directive must contain at least one condition. If the when directive contains more than one condition, all the child conditions must return true for the stage to execute. This is the same as if the child conditions were nested in an allOf  condition (see the examples below). 

More complex conditional structures can be built using the nesting conditions: not , allOf , or anyOf . Nesting conditions may be nested to any arbitrary depth. 

<img src='content_image/763248.jpg'>

## Built-in Conditions 

## branch 

Execute the stage when the branch being built matches the branch pattern given, for example: when { branch 'master' } . Note that this only works on a multibranch Pipeline. 

## environment 

Execute the stage when the specified environment variable is set to the given value, for example: when { environment name: 'DEPLOY_TO', value: 'production' } 

## expression 

