0
0
Jenkinsdevops~20 mins

Custom notification logic in Jenkins - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Custom Notification Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Jenkins Pipeline: Notification on Build Status
Given the following Jenkins pipeline snippet, what will be the output notification message if the build fails?
Jenkins
pipeline {
  agent any
  stages {
    stage('Build') {
      steps {
        script {
          currentBuild.result = 'FAILURE'
        }
      }
    }
  }
  post {
    failure {
      echo 'Build failed! Sending notification to team.'
    }
    success {
      echo 'Build succeeded! Sending success notification.'
    }
  }
}
ABuild failed! Sending notification to team.
BNo notification will be sent.
CBuild succeeded! Sending success notification.
DPipeline will error out due to invalid syntax.
Attempts:
2 left
💡 Hint
Check the post section and the currentBuild.result value.
Configuration
intermediate
2:00remaining
Configuring Email Notification in Jenkinsfile
Which of the following Jenkinsfile snippets correctly sends an email notification only when the build is unstable?
A
post {
  unstable {
    emailext subject: 'Build Unstable', body: 'Please check the build.', to: 'team@example.com'
  }
}
B
post {
  failure {
    emailext subject: 'Build Unstable', body: 'Please check the build.', to: 'team@example.com'
  }
}
C
post {
  always {
    emailext subject: 'Build Unstable', body: 'Please check the build.', to: 'team@example.com'
  }
}
D
post {
  success {
    emailext subject: 'Build Unstable', body: 'Please check the build.', to: 'team@example.com'
  }
}
Attempts:
2 left
💡 Hint
Look for the post condition that matches unstable builds.
Troubleshoot
advanced
2:00remaining
Why does the notification not send on build failure?
A Jenkins pipeline has this post block: post { failure { emailext subject: 'Build Failed', body: 'Check logs.', to: 'dev@example.com' } } But no email is sent when the build fails. What is the most likely cause?
AThe post block must be inside the stages block.
BThe failure block only runs on unstable builds, not failures.
CThe emailext plugin is not installed or configured properly.
DThe 'to' email address is missing in the emailext step.
Attempts:
2 left
💡 Hint
Check plugin installation and configuration.
🔀 Workflow
advanced
2:00remaining
Custom Notification Logic with Scripted Pipeline
In a scripted Jenkins pipeline, which snippet correctly sends a Slack notification only if the build result is SUCCESS or UNSTABLE?
A
if (currentBuild.result != 'FAILURE') {
  slackSend channel: '#alerts', message: 'Build passed or unstable'
}
B
if (currentBuild.result == 'FAILURE' || currentBuild.result == 'UNSTABLE') {
  slackSend channel: '#alerts', message: 'Build passed or unstable'
}
C
if (currentBuild.result == 'SUCCESS' && currentBuild.result == 'UNSTABLE') {
  slackSend channel: '#alerts', message: 'Build passed or unstable'
}
D
if (currentBuild.result == 'SUCCESS' || currentBuild.result == 'UNSTABLE') {
  slackSend channel: '#alerts', message: 'Build passed or unstable'
}
Attempts:
2 left
💡 Hint
Use logical OR to check for multiple results.
Best Practice
expert
3:00remaining
Best Practice for Avoiding Duplicate Notifications in Jenkins
Which approach best avoids sending duplicate notifications when using both 'post' blocks and manual notification steps inside stages?
ASend notifications both in stages and post blocks to ensure coverage.
BCentralize all notifications inside the 'post' block and avoid manual notifications in stages.
CUse manual notifications only and remove the post block entirely.
DSend notifications only in the first stage to avoid duplicates.
Attempts:
2 left
💡 Hint
Think about a single place to manage notifications.