CI/CD

Whenever a build fails, you would like to notify the team owning the job regarding the failure and provide failure reason. How would you do that?

Difficulty: unrated

Source: bregman-arie/devops-exercises by Arie Bregman

Answer

In Jenkins, you can use the "Email Notification" plugin to notify a team when a build fails. Here are the steps to set up email notifications for failed builds:

  1. Install the "Email Notification" plugin if it's not already installed in Jenkins.
  2. Go to the Jenkins job configuration page and click on "Configure".
  3. Scroll down to the "Post-build Actions" section and click on "Add post-build action".
  4. Select "Editable Email Notification" from the list of options.
  5. Fill out the required fields, such as the recipient email addresses, subject line, and email content. You can use Jenkins environment variables, such as ${BUILD_URL} and ${BUILD_LOG}, to include build-specific information in the email content.
  6. In the "Advanced Settings" section, select the "Send to recipients" option and choose "Only on failure" from the dropdown menu.
  7. Click "Save" to save the job configuration.

With this setup, Jenkins will send an email notification to the specified recipients whenever a build fails, providing them with the failure reason and any other relevant information.