• Get started
  • Documentation

Integrate with Jenkins

This article highlights a new alerting feature that's natively available in Jira Service Management which is gradually rolling out to some Jira Service Management Cloud customers. It may not yet be visible or available on your site.

Jenkins logo

What does the integration offer?

Use Jira Service Management Jenkins Integration to forward Jenkins build alerts to Jira Service Management. Jira Service Management determines the right people to notify based on on-call schedules– notifies via email, text messages (SMS), phone calls, and iOS & Android push notifications, and escalates alerts until the alert is acknowledged or closed.

How does the integration work?

When a build related problem occurs in Jenkins, an alert is created in Jira Service Management automatically through the integration.

Set up the integration

Jenkins is an API-based integration. Setting it up involves the following steps:

  • Add a Jenkins integration in Jira Service Management

  • Configure the integration in Jenkins

Add a Jenkins integration

Bidirectional integrations aren’t supported in Free and Standard plans. All the other integrations are supported at a team level in Free and Standard; however, for their outgoing part to work, you need to upgrade to a higher plan. To add any integration at a site level through Settings (gear icon) > Products (under JIRA SETTINGS) > OPERATIONS, you need to be either on Premium or Enterprise.

Adding an integration from your team’s operations page makes your team the owner of the integration. This means Jira Service Management only assigns the alerts received through this integration to your team.

To add a Jenkins integration in Jira Service Management, complete the following steps:

  1. Go to your team’s operations page.

  2. On the left navigation panel, select Integrations and then Add integration.

  3. Run a search and select “Jenkins”.

  4. On the next screen, enter a name for the integration.

  5. Optional: Select a team in Assignee team if you want a specific team to receive alerts from the integration.

  6. Select Continue.
    The integration is saved at this point.

  7. Expand the Steps to configure the integration section and copy the API URL and API key.
    You will use these while configuring the integration in Jenkins later.

  8. Select Turn on integration.
    The rules you create for the integration will work only if you turn on the integration.

Configure the integration in Jenkins

To configure the integration in Jenkins, complete the following steps:

  1. In the Jenkins machine, go to Manage Jenkins > Go to plugin manager > Available and search for Jira Service Management Plugin, select and install it.

  2. Go back to Jenkins main page.

  3. Go to Manage Jenkins > Configure System > Jira Service Management Notifier Settings to set global plugin configuration.

    • Enter the API URL and API key copied previously into appropriate fields. API URL is set to a default value but also can be configured.

    • Enter the Teams to notify and alert Tags.
      These fields are used as default settings, override them for specific jobs.

  4. Post-build action:

    1. Select Configure and activate Jira Service Management Plugin for the Jenkins Job.

    2. Scroll to the Post-Build Actions section of the project configuration.

    3. Select Add post-build action.

    4. Select Send Alert to Jira Service Management from the list displayed.
      The "Send Alert to Jira Service Management" section appears in the window.

    5. Select Save to save these changes.

  5. Job configuration:

    1. Go to Configure > Send Alert to Jira Service Management to configure the Jenkins Job settings for Jira Service Management plugin.

    2. Select Enable Sending Alerts to send an alert to Jira Service Management.

    3. Select Notify Build Start to send an alert to Jira Service Management that notifies on build start.

    4. Enter the API URL and API key copied previously into the appropriate fields. If these fields are filled, global settings are overridden.

    5. Enter the teams to notify and alert tags. Fill these fields to override global settings.

    6. Select the priority of the build status alert from Priority field.

    7. Select the priority of the build start status alert from Build Start Alert's Priority field.

Read more about the Jenkins plugin. Read more about the open source project.

Configure the Step function in Jira Service Management

You can call Jira Service Management Trigger Step function from your pipeline stages or post actions. Jira Service Management Step function can be called with the following parameters (or without any parameter): tags(comma separated), teams(comma separated), priority, apiKey and apiUrl
An example request would be the following:

step

1 jsm(tags: "tag1,tag2" , teams: "team1", priority: "P1")

API key and API Url

You can configure API key and API url from Manage Jenkins > Configure System > Jira Service Management Notifier Settings.
You can also override API key and API url from the step function call like following: jsm(apiKey: "myApiKey", apiUrl: "myApiUrl")

Sample pipeline script

 

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 pipeline { agent any stages { stage('pre') { steps { sh 'echo "pre success!"; exit 0' } } stage('post') { steps { sh 'echo "post success!"; exit 0' } } stage('Test') { steps { sh 'echo "Failed!"; exit 1' } } } post { always { echo 'This will always run' } success { echo 'This will run only if successful' jiraservicemanagement(tags: "informational") } failure { echo 'This will run only if failed' jiraservicemanagement(tags: "failure, critical", teams: "engineering", priority:"P1") } unstable { echo 'This will run only if the run was marked as unstable' jiraservicemanagement() } changed { echo 'This will run only if the state of the Pipeline has changed' echo 'For example, if the Pipeline was previously failing but is now successful' } } }

Still need help?

The Atlassian Community is here for you.