Integrate Jira Software 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. 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 Software Cloud site.

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

  • You're using a ‘Multibranch Pipeline’ in Jenkins (this is the only item supported in Jenkins today).

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

  • 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, you can read more here.


How to 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:

    • App name - Jenkins

    • App logo - A URL to the Jenkins logo, which will be used as an icon in the list of credentials. Eg: https://jenkins.yourcompany.com/logo.png

    • Server base URL - The URL to your Jenkins server. Eg: https://jenkins.yourcompany.com/


Install the Jenkins plugin

  1. Login 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.

Additional notes:


Set up Jenkins credentials

  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

  4. Select Test connection to make sure your credentials are valid for your Jira site.

How to use the integration

To start using the integration:

  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 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.


For sending build information

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'
       }
   }
}


For sending deployment information

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.

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'
       }
   }
}


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.



Last modified on Aug 23, 2019

Was this helpful?

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