What is the purpose of custom notification logic in Jenkins?
Custom notification logic allows Jenkins to send tailored messages based on build results or specific conditions, improving communication and response.
Click to reveal answer
beginner
Which Jenkins plugin is commonly used to implement custom notification logic?
The 'Email Extension Plugin' is commonly used to create custom email notifications with flexible triggers and content.
Click to reveal answer
intermediate
How can you trigger notifications only on build failures in Jenkins pipeline scripts?
Use conditional statements in the pipeline script to check if the build status is 'FAILURE' and then call the notification step.
Click to reveal answer
intermediate
What is the advantage of using scripted pipeline for custom notification logic?
Scripted pipelines offer more control and flexibility to define complex notification rules and customize message content dynamically.
Click to reveal answer
beginner
Name two common notification channels Jenkins can use besides email.
Jenkins can send notifications via Slack and Microsoft Teams using their respective plugins or webhooks.
Click to reveal answer
Which Jenkins plugin helps send customized email notifications?
APipeline Utility Steps
BEmail Extension Plugin
CDocker Plugin
DGit Plugin
✗ Incorrect
The Email Extension Plugin allows sending customized email notifications based on build status and conditions.
In a Jenkins pipeline, how do you send a notification only if the build fails?
ACheck if currentBuild.result == 'SUCCESS'
BSend notification unconditionally
CCheck if currentBuild.result == 'FAILURE'
DUse a post-build action without conditions
✗ Incorrect
You check the build result and send notifications only when it equals 'FAILURE' to avoid unnecessary alerts.
Which notification channel is NOT commonly integrated with Jenkins?
ATwitter
BMicrosoft Teams
CSlack
DEmail
✗ Incorrect
Twitter is not a common notification channel for Jenkins; Slack, Teams, and Email are standard.
What is a benefit of using scripted pipelines for notifications?
ALess flexibility
BAutomatic notifications without code
CNo need for plugins
DMore control over notification logic
✗ Incorrect
Scripted pipelines allow detailed control and customization of notification logic.
Which Jenkins feature helps you define when to send notifications?
ATriggers and conditions
BBuild history
CWorkspace cleanup
DSource code management
✗ Incorrect
Triggers and conditions let you specify when notifications should be sent, such as on failure or success.
Explain how you would implement custom notification logic in a Jenkins pipeline to notify only on failures.
Think about conditional checks and notification steps.
You got /4 concepts.
List common notification channels Jenkins supports and why customizing notifications is useful.
Consider integration options and benefits.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of using custom notification logic in Jenkins pipelines?
easy
A. To send notifications for every build regardless of status
B. To restart the Jenkins server automatically after each build
C. To disable all notifications permanently
D. To send notifications only when specific build conditions are met
Solution
Step 1: Understand notification goals
Custom notification logic aims to reduce noise by sending alerts only when necessary.
Step 2: Identify correct behavior
Sending notifications only on specific build results (like failure) keeps the team focused.
Final Answer:
To send notifications only when specific build conditions are met -> Option D
Quick Check:
Custom notifications = selective alerts [OK]
Hint: Think about reducing alert noise to stay focused [OK]
Common Mistakes:
Assuming notifications should always be sent
Confusing disabling notifications with custom logic
Believing Jenkins restarts after every build
2. Which Jenkins pipeline syntax correctly checks if the build failed before sending a notification?
easy
A. if (currentBuild.result = 'FAILURE') { notify() }
B. if (build.status == 'SUCCESS') { notify() }
C. if (currentBuild.currentResult == 'FAILURE') { notify() }
D. if (currentBuild.currentResult === FAILURE) { notify() }
Solution
Step 1: Identify correct property and comparison
Use currentBuild.currentResult to get build status and compare with string 'FAILURE'.
Step 2: Check syntax correctness
if (currentBuild.currentResult == 'FAILURE') { notify() } uses correct equality operator (==) and string comparison.
Final Answer:
if (currentBuild.currentResult == 'FAILURE') { notify() } -> Option C
Quick Check:
Correct property and comparison = if (currentBuild.currentResult == 'FAILURE') { notify() } [OK]
Hint: Use currentBuild.currentResult with 'FAILURE' string and == [OK]
Common Mistakes:
Using single equals (=) instead of double (==)
Comparing to SUCCESS instead of FAILURE
Missing quotes around 'FAILURE'
Using undefined variable FAILURE without quotes
3. Given this Jenkins pipeline snippet:
post {
failure {
script {
if (currentBuild.previousBuild?.result == 'SUCCESS') {
notify('Build failed after success')
}
}
}
}
What happens if the previous build was successful and the current build failed?
medium
A. Notification 'Build failed after success' is sent
B. No notification is sent
C. Notification is sent only if current build succeeded
D. Pipeline throws a syntax error
Solution
Step 1: Analyze condition in failure block
The post.failure block runs only if current build failed. Inside, it checks if previous build result was 'SUCCESS'.
Step 2: Evaluate condition outcome
If previous build was successful and current failed, condition is true, so notify is called with the message.
Final Answer:
Notification 'Build failed after success' is sent -> Option A
Quick Check:
Previous success + current failure triggers notification [OK]
Hint: Check previousBuild?.result and current failure block [OK]
Common Mistakes:
Thinking notification sends on success builds
Ignoring the safe navigation operator '?'
Assuming syntax error due to optional chaining
4. You wrote this Jenkins pipeline snippet to notify only on failure after success:
post {
failure {
script {
if (currentBuild.previousBuild.result == 'SUCCESS') {
notify('Failed after success')
}
}
}
}
But it sometimes throws a NullPointerException. What is the likely cause?
medium
A. notify function is undefined
B. previousBuild can be null, so accessing result causes error
C. failure block cannot contain if statements
D. currentBuild.previousBuild.result is always 'FAILURE'
Solution
Step 1: Identify potential null values
currentBuild.previousBuild can be null if no previous build exists.
Step 2: Understand error cause
Accessing result on null causes NullPointerException. Safe navigation operator ?. avoids this.
Final Answer:
previousBuild can be null, so accessing result causes error -> Option B
Quick Check:
Null previousBuild causes error without safe navigation [OK]
Hint: Use ?. to safely access previousBuild properties [OK]
Common Mistakes:
Ignoring possibility of null previousBuild
Assuming notify is always defined
Thinking failure block disallows if statements
5. You want to send a notification only when the build status changes from SUCCESS to FAILURE or from FAILURE to SUCCESS. Which Jenkins pipeline snippet correctly implements this logic?
hard
A. post {
failure {
script {
if (currentBuild.previousBuild?.result == 'SUCCESS') {
notify('Failed after success')
}
}
}
success {
script {
if (currentBuild.previousBuild?.result == 'FAILURE') {
notify('Succeeded after failure')
}
}
}
}
B. post {
success {
notify('Build succeeded')
}
failure {
notify('Build failed')
}
}
C. post {
always {
script {
if (currentBuild.previousBuild?.result != currentBuild.currentResult) {
notify('Build status changed')
}
}
}
}
D. post {
always {
notify('Build finished')
}
}
Solution
Step 1: Understand the requirement
Notify only when build status flips between SUCCESS and FAILURE, not on every build.
Step 2: Analyze each option
post {
failure {
script {
if (currentBuild.previousBuild?.result == 'SUCCESS') {
notify('Failed after success')
}
}
}
success {
script {
if (currentBuild.previousBuild?.result == 'FAILURE') {
notify('Succeeded after failure')
}
}
}
} checks previous build result and current build result in success and failure blocks separately, sending notifications only on status change.
Final Answer:
post {
failure {
script {
if (currentBuild.previousBuild?.result == 'SUCCESS') {
notify('Failed after success')
}
}
}
success {
script {
if (currentBuild.previousBuild?.result == 'FAILURE') {
notify('Succeeded after failure')
}
}
}
} -> Option A
Quick Check:
Status change detection needs previousBuild checks in success and failure blocks [OK]
Hint: Check previousBuild result differs from current in success and failure blocks [OK]
Common Mistakes:
Sending notifications on every build regardless of status change
Not checking previous build result
Using always block without condition
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.