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?
✗ 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?
✗ 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?
✗ 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?
✗ Incorrect
Running fewer or faster tests on feature branches saves build time and resources.
Which Jenkins pipeline syntax supports branch-specific behavior?
✗ 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.