How to trigger a PagerDuty alert when a Jenkins job fails

Read Time: 3 mins

We all know that Jenkins is a popular CI/CD tool. When you have a very important Jenkins job and it cannot fail, you will have to setup alerting for it. You might already have mail notification setup for the job, but it is not enough if the job is very important because mails could be ignored. In this article, I will explain how you can get a PagerDuty alert when a Jenkins job fails.

Step 1: Install Jenkins plugin ‘Pagerduty’

Fortunately we have a  Pagerduty  Jenkins plugin available to start with. Follow this article for the steps to install a Jenkins plugin and get Pagerduty plugin installed.

Step 2: Generate a Pagerduty API service integration key

Now we have Pagerduty plugin installed on Jenkins. Let’s generate a Pagerduty API service integration key. If you already have an API integration service attached to your escalation policy, you can just note down the  integration key  and skip below steps, else follow the steps to create a new API integration service in Pagerduty.

  1. Go to  https://your_account_name.pagerduty.com/services  and Click New Service .

2. On the Next page, give a name for your service, select Use our API directly as the Integration Type and choose your Escalation Policy. Then Click Add Service .

 

3. Now you will be landed on a page where Integration Key  is visible. Just note it down.

Step 3: Configure Jenkins Job to send Pagerduty alert

Hope you have the integration key with you. Keep it safe because why do you want someone else’s alert coming to you 😛 . Let’s configure our Jenkins Job to send Pagerduty alert whenever it fails.

1. Open your Jenkins UI and Click on the Jenkins Job. Here the job name is ‘test’.

 

2. On the next page, Click Configure .

 

3. Under Post-build Actions , Click Add post-build action  and select PagerDuty Incident Trigger .

 

4. Now fill in the details as mentioned below. Just paste the integration key that you have, to Service Integration Key  field.

 

Hurray, you have completed the course. See how the PagerDuty incident would look like.

One good thing is that whenever the Jenkins build is success, the alert would resolve by itself. You can add notification rules such as Mobile, Mail, SMS … etc in PagerDuty to notify the Oncall guy.

 

Thanks for the time taken to read my blog. Subscribe to this blog so that you don’t miss out anything useful (Checkout Right Sidebar for the Subscription Form) . Please also put your thoughts on this article as   comments .

A Site Reliability Engineer and an automation enthusiast.
Posts created 35

Begin typing your search term above and press enter to search. Press ESC to cancel.

Back To Top
x