// Declarative // pipeline { agent any stages { stage('Example') { steps { echo "Running ${env.BUILD_ID} on ${env.JENKINS_URL}" } } } } // Script // node { echo "Running ${env.BUILD_ID} on ${env.JENKINS_URL}" } 

## Setting environment variables 

Setting an environment variable within a Jenkins Pipeline is accomplished differently depending on whether Declarative or Scripted Pipeline is used. 

Declarative Pipeline supports an environment directive, whereas users of Scripted Pipeline must use the withEnv  step. 

// Declarative // pipeline { agent any environment { ① CC = 'clang' } stages { stage('Example') { environment { ② DEBUG_FLAGS = '-g' } steps { sh 'printenv' } } } } // Script // node { /* .. snip .. */ withEnv(["PATH+MAVEN=${tool 'M3'}/bin"]) { sh 'mvn -B verify' } } 

