-
Notifications
You must be signed in to change notification settings - Fork 248
Environment variables
Andrew Bayer edited this page Jan 10, 2017
·
6 revisions
Environment variables are set using name/value pairs:
pipeline {
environment {
FOO = "BAR"
}
agent { label "master" }
stages {
stage("foo") {
steps {
sh 'echo "FOO is $FOO"'
}
}
}
}
You can add many more variables, one per line, like so:
environment {
FOO = "BAR"
BAZ = "bang"
}
Environment variables can be set globally (like the above) or per stage. If they are set per stage, they only apply to the running stage. Other stages will not get those environment variables.
You can also access credentials (ie. secrets) and set them to environment variables. For example:
environment {
AWS_ACCESS_KEY_ID = credentials('AWS_ACCESS_KEY_ID')
AWS_SECRET_ACCESS_KEY = credentials('AWS_SECRET_ACCESS_KEY')
}
This looks up the secret text for each credential id
.
If you use username and password style of credentials, this is slightly different:
environment {
SAUCE_ACCESS = credentials('sauce-lab-dev')
}
This will actually set 3 variables:
-
SAUCE_ACCESS
containing<username>:<password>
-
SAUCE_ACCESS_USR
containing the username -
SAUCE_ACCESS_PSW
containing the password
Documentation
- Getting Started
- Running multiple steps
- Controlling your build environment
- Environment variables
- Reporting test results and storing artifacts
- Notifications
- Deployment and credentials
- Parallelism
- Triggering runs
- Parametrized pipelines
- Pipeline options and log rotation
- Jenkinsfile validation from the CLI
- Advanced pipeline authoring
- Syntax reference
- Version history and changes
Examples