Complete the code to run the stage only on the 'main' branch.
stage('Build') { when { branch [1] } steps { echo 'Building...' } }
The when directive with branch 'main' ensures the stage runs only on the main branch.
Complete the code to run the stage only when the environment variable 'DEPLOY' is set to 'true'.
stage('Deploy') { when { environment name: 'DEPLOY', value: [1] } steps { echo 'Deploying...' } }
The when directive checks if the environment variable DEPLOY equals 'true' to run the stage.
Fix the error in the when condition to run the stage only if the branch is 'feature'.
stage('Test') { when { branch [1] } steps { echo 'Testing...' } }
The branch name must be a quoted string like 'feature' in the when directive to avoid syntax errors.
Fill both blanks to run the stage only when the branch is 'release' and the environment variable 'RUN_TESTS' is 'yes'.
stage('Release') { when { allOf { branch [1] environment name: 'RUN_TESTS', value: [2] } } steps { echo 'Releasing with tests...' } }
The allOf condition requires both the branch to be 'release' and the environment variable RUN_TESTS to be 'yes' for the stage to run.
Fill all three blanks to run the stage only when the branch is 'hotfix', the environment variable 'DEPLOY' is 'true', and the build cause is 'SCMTrigger'.
stage('Hotfix Deploy') { when { allOf { branch [1] environment name: 'DEPLOY', value: [2] triggeredBy '[3]' } } steps { echo 'Deploying hotfix...' } }
The stage runs only if the branch is 'hotfix', the environment variable DEPLOY is 'true', and the build was triggered by SCMTrigger.