Process Flow - Conditional deployment logic
Start Pipeline
Check Condition
Deploy
End Pipeline
The pipeline starts, checks a condition, then either deploys if true or skips deployment if false, then ends.
pipeline {
agent any
stages {
stage('Deploy') {
when { branch 'main' }
steps { echo 'Deploying...' }
}
}
}| Step | Condition Checked | Condition Result | Action Taken | Output |
|---|---|---|---|---|
| 1 | Is branch 'main'? | True | Execute deploy stage | Deploying... |
| 2 | Pipeline ends | - | Finish | Pipeline completed successfully |
| Variable | Start | After Step 1 | After Step 2 |
|---|---|---|---|
| branch | main | main | main |
| deploy_stage_executed | false | true | true |
Jenkins conditional deployment uses 'when' to check conditions. If condition true, deploy stage runs. If false, stage is skipped. Common use: deploy only on 'main' branch. Helps avoid unwanted deployments.