0
0
Jenkinsdevops~5 mins

Branch-specific pipeline behavior in Jenkins - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is branch-specific pipeline behavior in Jenkins?
It means running different pipeline steps or stages depending on which branch of the code repository is being built.
Click to reveal answer
beginner
How can you detect the current branch in a Jenkins pipeline script?
You can use the environment variable 'BRANCH_NAME' inside the pipeline script to get the current branch name.
Click to reveal answer
intermediate
Show a simple Jenkins pipeline snippet that runs a test stage only on the 'develop' branch.
pipeline { agent any stages { stage('Test') { when { branch 'develop' } steps { echo 'Running tests on develop branch' } } } }
Click to reveal answer
beginner
What Jenkins pipeline directive helps to run steps only on a specific branch?
The 'when' directive with the 'branch' condition allows running steps only on a specific branch.
Click to reveal answer
beginner
Why is branch-specific pipeline behavior useful in CI/CD?
It lets you customize builds for different branches, like running full tests on 'main' but only quick checks on feature branches, saving time and resources.
Click to reveal answer
Which environment variable in Jenkins pipeline holds the current branch name?
AGIT_BRANCH
BCURRENT_BRANCH
CBRANCH_NAME
DPIPELINE_BRANCH
What Jenkins pipeline directive is used to run steps only on a specific branch?
Awhen
Bstage
Cagent
Denvironment
In a Jenkins pipeline, how do you specify a stage to run only on the 'main' branch?
Awhen { branch 'main' }
Bif (branch == 'main')
Cstage('main')
Dagent { label 'main' }
Why might you want different pipeline behavior on feature branches versus the main branch?
ATo deploy feature branches automatically
BTo save time by running fewer tests on feature branches
CTo disable builds on feature branches
DTo merge feature branches automatically
Which Jenkins pipeline syntax supports branch-specific behavior?
ANone of the above
BScripted pipeline only
CFreestyle jobs
DDeclarative pipeline
Explain how to configure a Jenkins pipeline to run different steps on 'main' and 'develop' branches.
Think about using 'when { branch 'branchName' }' inside stages.
You got /3 concepts.
    Describe why branch-specific pipeline behavior is important in continuous integration.
    Consider how different branches have different testing needs.
    You got /4 concepts.