How do parameters work in a Jenkins pipeline?
BeginnerConceptJenkins
Answer
The parameters directive adds a "Build with Parameters" form: string, booleanParam, choice, password, text. Values are available as params.NAME and as environment variables. On the first run of a branch the parameters are not yet registered, which is a known gotcha.
parameters {
choice(name: 'ENV', choices: ['dev', 'staging', 'prod'], description: 'Target')
booleanParam(name: 'RUN_E2E', defaultValue: true)
}
// usage: echo "Deploying to ${params.ENV}"
More on Jenkins
What is Jenkins and how is its architecture organised?BeginnerWhat are executors, nodes and labels in Jenkins?IntermediateWhy should you not run builds on the Jenkins controller?BeginnerHow do inbound (JNLP/WebSocket) and SSH agents connect to the controller?IntermediateWhat is a Jenkinsfile and where does it live?BeginnerDeclarative versus Scripted Pipeline: what are the differences?Intermediate