Parameters and when Conditions
Scenario: An arbitrary environment string typo creates an unintended deployment target.
Pipeline example
pipeline { agent any; parameters { choice(name: 'TARGET', choices: ['dev','staging']) }; stages { stage('Deploy') { when { expression { params.TARGET == 'staging' } }; steps { echo 'deploy' } } } }
Parameters are a public job interface
Declarative offers string, text, boolean, choice, and password parameters, with plugins adding more. Pipeline reads typed values from params while environment exports may stringify them. A choice list reduces mistakes but cannot replace validation at every trigger path. Reject unknown environments, malformed digests, unsafe paths, and contradictory combinations before allocating a costly or privileged agent.
When supports branch, tag, change request, environment, expression, allOf, anyOf, and not. BeforeAgent true can evaluate supported policy before provisioning the stage node. Expression must return a boolean: the Groovy string false is truthy and can unexpectedly enable deployment. Keep required release policy independent of user-controlled values.
Make skipped stages explainable
Use immutable artifact digests and constrained target choices instead of arbitrary branch and hostname strings. Defaults should be conservative because API and scheduled callers may omit values. Jenkinsfile parameter changes can require an initial run before the job form reflects them, so account for bootstrap and old bookmarked URLs.
Test missing input, whitespace, case differences, stale values, unauthorized callers, replay, and invalid combinations. Record accepted non-secret parameters and why a condition skipped. A safe interface fails closed before side effects and cannot turn a spelling error into creation of an unintended deployment target.
Goal: Practice the concrete behavior in jenkins-parameterized-deploy. Learn sections have no Jenkins terminal; the Jenkins lab opens the real shared service in a new full-screen tab inside your private folder.