-
Notifications
You must be signed in to change notification settings - Fork 248
Parametrized pipelines
Andrew Bayer edited this page Aug 13, 2018
·
11 revisions
You can define pipelines as requiring some parameters (from the user, or from an api call) before they can start. These parameters can control what the pipeline does, for example what environment it may be deploying applications into.
Valid parameter types are booleanParam
, choice
, file
, text
, password
, run
, or string
.
pipeline {
agent any
parameters {
booleanParam(defaultValue: true, description: '', name: 'userFlag')
}
stages {
stage("foo") {
steps {
echo "flag: ${params.userFlag}"
}
}
}
}
This will ask for a true/false value when the pipeline is run.
You can ask for string input:
string(defaultValue: true, description: '', name: 'userFlag')
You can also ask for multiple choice items, and stack up the input required:
parameters {
string(defaultValue: "TEST", description: 'What environment?', name: 'userFlag')
choice(choices: ['US-EAST-1', 'US-WEST-2'], description: 'What AWS region?', name: 'region')
}
Although parameters are available in env
they currently are created before the first time the pipeline is run, therefore you should access them via params
:
sh "echo ${params.region}"
They might eventually be available in env
. (JENKINS-40241)
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