Step 1: Check when syntax for environment variable
The correct syntax uses environment name: 'DEPLOY', value: 'true' or expression blocks, not direct comparison.
Step 2: Identify invalid usage
Using environment DEPLOY == 'true' is invalid and causes syntax error.
Final Answer:
The environment condition is invalid syntax -> Option D
Quick Check:
Invalid environment condition syntax = D [OK]
Hint: Use correct when { environment name: 'VAR', value: 'val' } syntax [OK]
Common Mistakes:
Writing direct comparisons inside when
Placing when inside steps
Misusing stage names
5. You want to deploy only if the branch is 'release' and the environment variable DEPLOY is 'yes'. Which when block correctly implements this in a declarative Jenkins pipeline?
hard
A. when { allOf { branch 'release'; environment name: 'DEPLOY', value: 'yes' } }
B. when { branch 'release' && environment DEPLOY == 'yes' }
C. when { branch 'release' environment DEPLOY == 'yes' }
D. when { anyOf { branch 'release'; environment name: 'DEPLOY', value: 'yes' } }
Solution
Step 1: Understand combining conditions in when
Use allOf to require both conditions true simultaneously.
Step 2: Check syntax for branch and environment conditions
when { allOf { branch 'release'; environment name: 'DEPLOY', value: 'yes' } } correctly uses allOf with branch 'release' and environment name: 'DEPLOY', value: 'yes'.
Step 3: Identify errors in other options
Options A and C use invalid syntax; D uses anyOf which means either condition, not both.
Final Answer:
when { allOf { branch 'release'; environment name: 'DEPLOY', value: 'yes' } } -> Option A
Quick Check:
Use allOf for AND conditions = B [OK]
Hint: Use allOf to combine multiple when conditions [OK]
Common Mistakes:
Using anyOf instead of allOf
Writing invalid combined expressions
Misusing environment condition syntax
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.