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
✗ Incorrect
BRANCH_NAME is the standard environment variable Jenkins sets for the current branch in multibranch pipelines.
What Jenkins pipeline directive is used to run steps only on a specific branch?
Awhen
Bstage
Cagent
Denvironment
✗ Incorrect
The 'when' directive controls conditional execution, including branch-specific conditions.
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' }
✗ Incorrect
The 'when { branch 'main' }' syntax is the correct way to conditionally run a stage on the 'main' branch.
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
✗ Incorrect
Running fewer or faster tests on feature branches saves build time and resources.
Which Jenkins pipeline syntax supports branch-specific behavior?
ANone of the above
BScripted pipeline only
CFreestyle jobs
DDeclarative pipeline
✗ Incorrect
Declarative pipeline syntax includes the 'when' directive for branch-specific conditions.
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.
Practice
(1/5)
1.
Which Jenkins pipeline syntax runs a stage only on the main branch?