Failing Builds? Integrate Jenkins & Jira for a sunny day

jenkins_jira_integration_testautonationJenkins and Jira are probably the two most used systems in the tech industry, but are you using them to their full potential?

Jenkins: “A continuous integration and continuous delivery application.” Read more.
Jira: “JIRA is an issue management platform.” – Read more.

Why should I integrate Jenkins with Jira?

How many times have you logged into your Jenkins system and while browsing around find some terrifying thunder images next to some Jenkins jobs? The worst bit, no one knew that these builds failed. Moreover, if they keep on failing, the tendency is that they will continue to fail as no one has the time to fix this. “That build has been failing for months now, it is probably not important” is the reassuring answer you get. Even though the automatic answer is “it is not important” no one dares to delete or pause the job.

Now if the situation comes to this, the only solution is to be persistent enough for one of the developers to get the job done (pun intended). This article is more of a prevention than a cure.

The main problem with most Jenkins setups is that there are so many Jenkins jobs that it is impossible to manually check that these jobs are all passing and working as they should. So if “less important” jobs start failing, the probability is that no one will know about this. There are many ways how one can trigger notifications when a Jenkins job fails: HipChat, Slack, SMS, E-mail and Jira.

The one I found most useful: Jira, due to the following reasons:

1. If the problem is longer than a 1-minute job, a Jira ticket still needs to be opened.
2. Jira will automatically assign a ticket to a team or a person. Long gone are the days where no one knows who is responsible for that job.
3. Jira keeps a history of all tickets created. Making it easy to see how many times the same build has failed in the past few weeks.

Did I convince you yet? The best part, it is super simple thanks to the list of plugins available. The following steps will include how to integrate your jobs to Jira.

Let’s Get started

For a non-pipeline job, I use JiraTestResultReporter. The documentation is excellent, and once you download the plugin, you only have a few steps to begin creating tickets automatically.

  1. First of all, I would suggest creating a Jenkins user in Jira. I recommend this for one simple reason: to keep track of the tickets opened. If you use your own personal account, tickets you create manually and tickets created by Jenkins will get mixed up and will become a bit more difficult for you to sort. The plugin documentation also suggests this, due to security reasons.
  2. Once this user is set up, next step is to connect Jenkins to Jira. To do this, you must go to Manage Jenkins -> Configure System -> JiraTestResultReporter
  3. Here you must add your Jira URL, Jira Username (which you have just created) & Password. Click on “Validate Settings” to make sure that everything is working fine.

All good?

4. Cool, next we can define some Global Settings using both Jenkins and also the Plugins Custom Environment Variables. These can be set as Default, and then overridden when setting different jobs.

5. Let’s configure the plugin to be used in our jobs. I usually use this plugin with jobs that output JUnit reports. So navigate to the job you would like tickets to be opened for, and select “Configure”. Scroll down to the “Post Build” section where you should already have the Junit Publisher set up and click on “Additional Reporting”. From the drop-down select JiraTestResultReporter.

We’re nearly done.

6. Now you just need to set some options. As I mentioned before, you can overwrite the fields set in the global configuration such as the “Summary” and “Description”. The best part is that you can also select “Auto Raise issues” which will automatically create and link the test to the Jira ticket, meaning that if the same test fails multiple times, it will always link you to the same ticket and not create multiples. Awesome right :)?

Your Jenkins jobs should be all sunny in no time, all thanks to this simple integration.

Do you have any questions? Or maybe have any ideas of how such integrations can be improved? Leave us a message below.

P.S. we are looking for guest authors to write on TestAutonation. Interested? Contact Us.

Leave a Reply

Your email address will not be published. Required fields are marked *

4 − 3 =