0
0
Jenkinsdevops~10 mins

Custom notification logic in Jenkins - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to send an email notification after a build.

Jenkins
post {
  [1] {
    mail to: 'team@example.com', subject: 'Build Status', body: 'The build is complete.'
  }
}
Drag options to blanks, or click blank then click option'
Aalways
Bfailure
Csuccess
Dunstable
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'success' will only send emails on successful builds.
Using 'failure' will only send emails on failed builds.
2fill in blank
medium

Complete the code to notify only when the build fails.

Jenkins
post {
  [1] {
    mail to: 'dev@example.com', subject: 'Build Failed', body: 'Please check the build logs.'
  }
}
Drag options to blanks, or click blank then click option'
Afailure
Bunstable
Csuccess
Dalways
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'always' sends notifications even on success.
Using 'success' will never send notifications on failure.
3fill in blank
hard

Fix the error in the notification script to send email only on unstable builds.

Jenkins
post {
  [1] {
    mail to: 'qa@example.com', subject: 'Build Unstable', body: 'Check the unstable build details.'
  }
}
Drag options to blanks, or click blank then click option'
Afailure
Bsuccess
Calways
Dunstable
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'failure' will not trigger on unstable builds.
Using 'always' sends notifications regardless of build status.
4fill in blank
hard

Fill both blanks to send a Slack notification only on successful builds with a custom message.

Jenkins
post {
  [1] {
    slackSend channel: '#builds', message: [2]
  }
}
Drag options to blanks, or click blank then click option'
Asuccess
B'Build succeeded! 🎉'
C'Build failed! ❌'
Dfailure
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'failure' block will not send notifications on success.
Using a failure message in the success block confuses the notification.
5fill in blank
hard

Fill all three blanks to create a notification that sends an email on failure, Slack message on unstable, and logs a message always.

Jenkins
post {
  failure {
    mail to: '[1]', subject: 'Build Failed', body: 'Check logs.'
  }
  unstable {
    slackSend channel: '[2]', message: '[3]'
  }
  always {
    echo 'Build finished.'
  }
}
Drag options to blanks, or click blank then click option'
Adev-team@example.com
B#qa-alerts
C'Build is unstable, please review.'
Dops@example.com
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong email address for failure notifications.
Mixing up Slack channels or messages for unstable builds.