branchName to hold the branch name.branchName is 'main'.echo "Running full tests" if on main branch.echo "Running quick checks" if on any other branch.branchName to hold the branch name.branchName is 'main'.echo "Running full tests" if on main branch.echo "Running quick checks" if on any other branch.branchName and set it to the string 'main'.Use def branchName = 'main' to create the variable.
if statement that checks if branchName is equal to 'main'.Use if (branchName == 'main') to check the branch.
if block, add sh 'echo "Running full tests"'. Add an else block with sh 'echo "Running quick checks"'.Use sh 'echo "Running full tests"' inside the if block and sh 'echo "Running quick checks"' inside the else block.
println statement after the if-else block to print "Building branch: " followed by the branchName variable.Use println("Building branch: ${branchName}") to print the branch name.
Which Jenkins pipeline syntax runs a stage only on the main branch?
when { branch 'branchName' } to run stages on specific branches.main branchwhen { branch 'main' } to target the main branch.Which snippet correctly uses Jenkins declarative pipeline syntax to run a stage only on branches dev or feature/*?
stage('Test') {
when {
???
}
steps {
echo 'Running tests'
}
}anyOf { branch 'name'; branch 'pattern' } to run if any branch matches.anyOf { branch 'dev'; branch 'feature/*' } runs the stage on either branch.Given this Jenkins pipeline snippet, what will be the output if the branch is feature/login?
pipeline {
agent any
stages {
stage('Build') {
when { branch 'main' }
steps { echo 'Building main branch' }
}
stage('Test') {
when { branch 'feature/*' }
steps { echo 'Testing feature branch' }
}
}
}Identify the error in this Jenkins pipeline snippet that tries to run a stage only on the release branch:
stage('Deploy') {
when {
branch release
}
steps {
echo 'Deploying release branch'
}
}branch 'release'.branch release lacks quotes, causing a syntax error.You want a Jenkins pipeline stage to run on all branches except main and develop. Which when condition correctly implements this?
anyOf and negate with not.not { anyOf { branch 'main'; branch 'develop' } } runs on all branches except these two.Pass the test and this pattern moves unknown