// 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 . 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. 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. Execute the stage when the specified environment variable is set to the given value, for example: when { environment name: 'DEPLOY_TO', value: 'production' } branch Built-in Conditions environment expression when Require d No Parame ters None Allowed Inside a  stage  directive 94