0
0
Jenkinsdevops~5 mins

Conditional deployment logic in Jenkins - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is conditional deployment logic in Jenkins?
It is a way to control when and how deployment steps run based on specific conditions, like branch name or build status.
Click to reveal answer
beginner
How can you check the branch name in a Jenkins pipeline to decide deployment?
Use the environment variable 'BRANCH_NAME' inside a 'when' block to run deployment only on certain branches.
Click to reveal answer
intermediate
What Jenkins pipeline syntax allows running steps only if the build is successful?
The 'post' section with 'success' condition or a 'when' block checking 'currentBuild.currentResult == "SUCCESS"'.
Click to reveal answer
beginner
Explain the use of the 'when' directive in Jenkins pipelines.
The 'when' directive lets you specify conditions to decide if a stage should run, like checking branch, environment variables, or build results.
Click to reveal answer
beginner
How do you implement a conditional deployment only on the 'main' branch in a declarative Jenkins pipeline?
Use a 'when { branch 'main' }' block inside the deployment stage to run it only when building the 'main' branch.
Click to reveal answer
Which Jenkins pipeline directive is used to run a stage only on a specific branch?
Aenvironment
Bwhen
Cpost
Dagent
How do you check if the build was successful before deploying in Jenkins pipeline?
AUse 'agent any'
BUse 'when { branch "main" }'
CUse 'environment { BUILD_STATUS = "SUCCESS" }'
DUse 'post { success { ... } }'
What environment variable commonly holds the branch name in Jenkins pipelines?
ABRANCH_NAME
BBUILD_ID
CJOB_NAME
DDEPLOY_ENV
Which of these is NOT a valid condition for the 'when' directive in Jenkins declarative pipelines?
Abranch
Bsuccess
Cagent
Denvironment
What happens if the 'when' condition in a Jenkins stage is false?
AThe stage is skipped
BThe pipeline pauses
CThe pipeline fails
DThe stage runs anyway
Describe how you would set up a Jenkins pipeline to deploy only when building the 'main' branch and the build is successful.
Think about combining branch check and build status in pipeline syntax.
You got /3 concepts.
    Explain the purpose of conditional deployment logic in Jenkins and why it is useful.
    Consider real-life situations where you only want to deploy safe and correct code.
    You got /4 concepts.