Integrate Jira Cloud with Jenkins

Integrating with self-hosted tools using OAuth

On this page

Still need help?

The Atlassian Community is here for you.

Ask the community

This integration exists to provide a free, easy, secure, and reliable way to connect your Jenkins server, running behind the firewall, and Jira Software Cloud and/or Jira Service Management Cloud. Simply add a few extra lines in the Jenkinsfile that defines your pipeline steps and the integration will start sending build and deployment data to Jira and associate that information with the relevant Jira issues.

This gives your entire team additional visibility and context on every issue detail view in Jira, showing the latest build status or if that work has been successfully deployed to an environment.

You can also use this information to search across issues using the Jira Query Language (JQL), easily answering questions like “which issues in the current sprint have been deployed to production”. You can even add these as quick filters on your boards!

Before you begin

Time: 15-30 mins

Prerequisites

  • You're a site administrator of your Jira Cloud site.

  • You're an admin in Jenkins and you can install, update, and delete plugins.

  • Your team should be adding issue keys (e.g. FUSE-123) as part of their commit messages (for deployment information) and branch names (for build information). If your team isn't already following this pattern, learn more about referencing issues in your development work

  • You can edit the Jenkinsfile in your source code/repo for the pipeline(s) you want to use this integration with.

Link Jira Software Cloud with Jenkins

Create OAuth credentials in Jira for Jenkins

  1. Navigate to Jira home > Jira settings > Apps.

  2. Select OAuth credentials.

  3. Select Create credentials.

  4. Enter the following details:

Install the Jira Cloud plugin for Jenkins

  1. Log in to your Jenkins server and navigate to the Plugin Manager.

  2. Select the 'Available' tab and search for 'Atlassian Jira Software Cloud' as the plugin name then install it.

The open-source plugin is hosted at GitHub. You can check it out here.


Add your OAuth credentials to Jenkins

  1. In Jenkins, go to Manage Jenkins > Configure System screen and scroll to the Jira Software Cloud integration section.

  2. Select Add Jira Cloud Site > Jira Cloud Site. The Site name, ClientID, and Secret fields display.

  3. Enter the following details:

    • Site name: The URL for your Jira Cloud site, for example yourcompany.atlassian.net.

    • Client ID: Copy from OAuth credentials screen (Client ID column).

    • Secret: Select Add > Jenkins.

      • For Kind, select Secret text.

      • For Secret, copy from OAuth credentials screen (Secret column).

      • For Description, provide a helpful description

    • Secret: Select your newly created secret.
  4. Select Test connection to make sure your credentials are valid for your Jira site.

  5. Select Save.

Use the Jira cloud plugin for Jenkins

Generate snippets

  1. Go into a specific pipeline in Jenkins.

  2. From the left-hand menu, select Pipeline Syntax.

  3. In the Snippet Generator, select jiraSendDeploymentInfo or jiraSendBuildInfo, or checkGatingStatus from the dropdown list of Sample Steps and fill in the relevant details.

  4. Select Generate Pipeline Script and copy/paste the output into your Jenkinsfile, wherever you want to notify Jira.

Send build information to Jira

This is an example snippet of a very simple ‘build’ stage set up in a Jenkinsfile. After the pipeline is run, it will post the build information to your Jira Cloud site by looking at the branch name. If there is a Jira issue key (e.g. “TEST-123”) in the branch name, it will send the data over to Jira.

stage('Build') {
   steps {
       echo 'Building...'
   }
   post {
       always {
           jiraSendBuildInfo site: '<sitename>.atlassian.net'
       }
   }
}


Send deployment information to Jira

This is an example snippet of a stage that runs on any change to the master branch. Again, we use a post step to send deployment data to Jira and the relevant issues. Here, the environmentId, environmentName, and environmentType need to be set to whatever you want to appear in Jira. Include State and ServiceIds to add more context to deployment progress, result, and what is affected.

stage('Deploy - Production') {
   when {
       branch 'master'
   }
   steps {
       echo 'Deploying to Production from master...'
   }
   post {
       always {
           jiraSendDeploymentInfo site: '<sitename>.atlassian.net', environmentId: 'us-prod-1', environmentName: 'us-prod-1', environmentType: 'production'
       }
   }
}


Include environment and service details as parameters

Site, environment, and service details – as parameters – are exposed to build as environment variables.

To add your Jira site, environment, and service details as parameters in your Jenkins pipeline:

  1. Go to Jenkins and select a pipeline.

  2. Select Configure.

  3. Select the General tab.

  4. Check This project is parameterized.

  5. Select Add Parameter > String parameter.

  6. Enter the name, default value, and description for your parameter.

  7. Select Save.


Specify custom logic to get issue keys

By default, the plugin extracts issue keys from all the commit messages in the change log of the build. It is possible to override this behavior to add your own logic and supply the list issue keys as an issueKeys parameter.

jiraSendDeploymentInfo site: '<sitename>.xyz.net', 
environmentId: 'us-prod1', environmentName: 'us-prod2', 
environmentType: 'production', issueKeys: ['DEV-001', 'DEV-002']


View development information to Jira

If set up properly, whenever you make a commit or merge a PR in your SCM tool, like Bitbucket or GitHub, it should run the Jenkins pipeline you have specified for that repo. The build and deployment information will be visible on the issue detail view along the right-hand side. Learn how to view development information for an issue.

Link Jira Service Management Cloud with Jenkins

Learn how you can automate change management processes using Jira Service Management and Jenkins.

Learn more


Last modified on Nov 17, 2021

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.