Challenge - 5 Problems
Email Notification Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
Email Notification Syntax in Jenkins Pipeline
What is the output when the following Jenkins pipeline snippet runs, assuming the email plugin is correctly configured and the build fails?
Jenkins
pipeline {
agent any
stages {
stage('Failing Stage') {
steps {
script {
error('Forced failure')
}
}
}
}
post {
failure {
emailext(
subject: "Build Failed: ${env.JOB_NAME} #${env.BUILD_NUMBER}",
body: "The build failed. Check the console output at ${env.BUILD_URL}console",
to: 'team@example.com'
)
}
}
}Attempts:
2 left
💡 Hint
Check the 'post' section and the 'failure' condition in Jenkins pipelines.
✗ Incorrect
The 'post' block with 'failure' triggers only when the build fails. The emailext step sends an email with the specified subject and body to the given recipient.
❓ Troubleshoot
intermediate2:00remaining
Troubleshooting Missing Email Notifications
A Jenkins pipeline uses the emailext step in the post section to send failure notifications. However, no emails are received even though the build fails. Which of the following is the most likely cause?
Attempts:
2 left
💡 Hint
Check Jenkins global configuration for email settings.
✗ Incorrect
If the SMTP server is not set or unreachable, Jenkins cannot send emails even if the pipeline script is correct.
❓ Configuration
advanced2:00remaining
Configuring Email Recipients Dynamically
Which Jenkins pipeline snippet correctly sends an email notification to a dynamic list of recipients stored in a variable called 'emailList' when the build is unstable?
Jenkins
def emailList = 'dev1@example.com,dev2@example.com' pipeline { agent any stages { stage('Test') { steps { script { currentBuild.result = 'UNSTABLE' } } } } post { unstable { // Which option correctly sends email to emailList? } } }
Attempts:
2 left
💡 Hint
Use Groovy string interpolation with double quotes for variables.
✗ Incorrect
In Jenkins pipeline Groovy scripts, variables inside double quotes are interpolated. Single quotes or no quotes do not interpolate variables correctly.
🔀 Workflow
advanced2:00remaining
Email Notification Workflow with Multiple Conditions
In a Jenkins pipeline, you want to send an email notification only if the build is either unstable or failed, but not on success or aborted. Which post block configuration achieves this?
Attempts:
2 left
💡 Hint
Use separate blocks for failure and unstable conditions.
✗ Incorrect
Jenkins pipeline post blocks support separate conditions like failure and unstable. Combining them in one block with a comma is invalid syntax.
✅ Best Practice
expert2:00remaining
Best Practice for Sensitive Email Credentials in Jenkins Pipelines
What is the best practice to securely use SMTP credentials for sending email notifications in Jenkins pipelines?
Attempts:
2 left
💡 Hint
Consider Jenkins secure credentials management features.
✗ Incorrect
Using Jenkins credentials store with withCredentials block keeps sensitive data encrypted and avoids exposing secrets in code or logs.