pipeline {
agent any
environment {
DISABLE_AUTH = 'true'
DB_ENGINE = 'sqlite'
}
stages {
stage('Build') {
steps {
sh 'printenv'
}
}
}
}
Environment variables can be set globally, like the example below, or per stage. As you might expect, setting environment variables per stage means they will only apply to the stage in which they’re defined.
pipeline {
agent any
environment {
DISABLE_AUTH = 'true'
DB_ENGINE = 'sqlite'
}
stages {
stage('Build') {
steps {
sh 'printenv'
}
}
}
}
This approach to defining environment variables from within the Jenkinsfile
can be very useful for instructing scripts, such as a Makefile
, to configure
the build or tests differently to run them inside of Jenkins.
Another common use for environment variables is to set or override "dummy"
credentials in build or test scripts. Because it’s (obviously) a bad idea to
put credentials directly into a Jenkinsfile
, Jenkins Pipeline allows users to quickly
and safely access pre-defined credentials in the Jenkinsfile
without ever
needing to know their values.
See Handling credentials in the User Handbook for more information.
Please submit your feedback about this page through this quick form.
Alternatively, if you don't wish to complete the quick form, you can simply indicate if you found this page helpful?
See existing feedback here.