Environment Variables

(this post if part of the material I cover in my devops course)

Here's an example of a file with environment variables:

 1pipeline {
 2    agent any
 3
 4    environment {
 5        globalvar = 'global'
 6    }
 7
 8    stages {
 9        stage('stage1') {
10            environment {
11                localvar = 'local'
12             }
13            steps {
14                echo localvar
15                echo globalvar
16            }
17        }
18        stage('stage2') {
19            steps {
20                echo localvar
21                echo globalvar
22            }
23        }
24    }
25}

You can see that:

  • There is a global environment section
  • There is also a stage local environment section
  • This pipeline is going to fail (why?)
  • see this for more details