The shell command sh 'exit 1' causes the build to fail.
Step 2: Determine which post blocks run on failure
The failure block runs on failure, printing 'Build failed'. The always block runs regardless, printing 'Build finished'. The success block does not run.
Final Answer:
Build failed
Build finished -> Option A
Quick Check:
Failure + always blocks run on failure [OK]
Hint: Failure and always blocks run on failure [OK]
Common Mistakes:
Assuming success block runs on failure
Ignoring the always block
Thinking only failure block runs
4. Identify the error in this Jenkins pipeline post section:
C. The 'cleanup' block is invalid in the post section
D. The 'echo' commands must be inside 'steps' block
Solution
Step 1: Review valid post condition blocks
Valid blocks are success, failure, always, unstable, and changed. There is no cleanup block.
Step 2: Check syntax of echo commands
The echo commands can be used directly in post blocks. The order of blocks does not matter.
Final Answer:
The 'cleanup' block is invalid in the post section -> Option C
Quick Check:
Only success, failure, always allowed [OK]
Hint: Post section allows only specific blocks like success, failure, always [OK]
Common Mistakes:
Adding unsupported blocks like 'cleanup'
Thinking block order matters
Wrapping echo in steps inside post (not needed)
5. You want to send a notification only if the build fails, but also always archive the build logs regardless of the result. Which post section correctly implements this?
hard
A. post { failure { mail to: 'team@example.com' archiveArtifacts 'logs/**' } }
B. post { always { mail to: 'team@example.com' } failure { archiveArtifacts 'logs/**' } }
C. post { success { mail to: 'team@example.com' } always { archiveArtifacts 'logs/**' } }
D. post { failure { mail to: 'team@example.com' } always { archiveArtifacts 'logs/**' } }
Solution
Step 1: Identify notification condition
Notification should run only on failure, so it belongs in the failure block.
Step 2: Identify archiving condition
Archiving logs should happen always, so it belongs in the always block.
Step 3: Check syntax correctness
post { failure { mail to: 'team@example.com' } always { archiveArtifacts 'logs/**' } } correctly separates the two actions into failure and always blocks. post { failure { mail to: 'team@example.com' archiveArtifacts 'logs/**' } } puts both actions in the failure block, so archiving occurs only on failure.
Final Answer:
post { failure { mail to: 'team@example.com' } always { archiveArtifacts 'logs/**' } } -> Option D
Quick Check:
Failure for notify, always for archive [OK]
Hint: Use failure for notify, always for archive [OK]
Common Mistakes:
Putting always steps inside failure block
Sending notifications on success instead of failure
Missing proper syntax for multiple steps
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.