How to Integrate Jenkins with Jira

How to Integrate Jenkins with Jira

I still remember the moment my manager asked “which Jira tickets went out in last night’s release” and I had to manually cross-reference commit messages with ticket IDs for twenty minutes. That was the day I set up the Jira integration in Jenkins and never looked back. When it’s wired correctly, every build automatically comments on the relevant Jira issue, transitions tickets through workflow states, and gives your product team a clear paper trail from code to deployment. Here’s exactly how I set it up, and how you can too.

Why Connect Jenkins to Jira

Jira tracks what needs to be done; Jenkins tracks what actually happened to the code. Bridging them closes the loop between planning and execution. With the integration in place you get:

How the Integration Works Internally

The connection is built on the Jira Plugin for Jenkins, which talks to Jira’s REST API. Jenkins scans commit messages or branch names for issue keys (like PROJ-123) using a regex pattern, then uses Jira’s API to post comments or update issue fields. Authentication happens through a Jira user account (or, for Jira Cloud, an API token) stored as a Jenkins credential. On Jira’s side, nothing special needs to be installed for basic commenting, but for advanced workflows you may want the Jira Software REST API scopes enabled for the integration user.

There are two common flavors of this integration:

  1. Passive integration – Jenkins scans commits and posts comments to Jira automatically (no Jira-side plugin needed beyond REST API access).
  2. Active integration – using the Jira plugin’s build steps to explicitly transition issues, add labels, or attach build artifacts to specific tickets.

Step 1: Install the Jira Plugin in Jenkins

Go to Manage JenkinsPluginsAvailable plugins, search for Jira Plugin, and install it. Or from the CLI:

java -jar jenkins-cli.jar -s http://localhost:8080/ install-plugin jira -restart

Step 2: Create a Jira API Token or Service Account

For Jira Cloud:

  1. Log in to Jira, go to Account SettingsSecurityCreate and manage API tokens.
  2. Click Create API token, name it jenkins-integration, and copy the value immediately (it’s shown only once).

For Jira Server/Data Center, create a dedicated service account with permission to comment and transition issues in the relevant projects, and use its username/password as the credential.

Step 3: Configure the Jira Site in Jenkins

  1. Go to Manage JenkinsSystem.
  2. Scroll to the Jira section and click Add Jira Site.
  3. Enter your Jira base URL, e.g. https://mycompany.atlassian.net.
  4. Add a credential (username = your Jira email, password = the API token).
  5. Click Test Connection to confirm.

Step 4: Add Credentials via Jenkins CLI (Optional)

If you manage credentials as code:

echo '<com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl>
  <scope>GLOBAL</scope>
  <id>jira-creds</id>
  <username>jenkins-bot@mycompany.com</username>
  <password>YOUR_API_TOKEN</password>
</com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl>' | \
java -jar jenkins-cli.jar -s http://localhost:8080/ create-credentials-by-xml system::system::jenkins _

Step 5: Enable Automatic Issue Linking in a Job

For freestyle jobs, check Update relevant Jira issues under the job configuration, which automatically comments on any Jira key found in commit messages.

For pipeline jobs, use the jiraComment and related steps directly:

pipeline {
    agent any

    stages {
        stage('Checkout') {
            steps {
                git branch: 'main', url: 'https://github.com/myorg/myapp.git'
            }
        }
        stage('Build') {
            steps {
                sh './gradlew build'
            }
        }
        stage('Notify Jira') {
            steps {
                script {
                    def issueKeys = sh(
                        script: "git log -1 --pretty=%B | grep -oE '[A-Z]+-[0-9]+' || true",
                        returnStdout: true
                    ).trim().split("\\n")

                    for (key in issueKeys) {
                        if (key) {
                            jiraComment issueKey: key, body: "Build ${env.BUILD_NUMBER} completed successfully. ${env.BUILD_URL}"
                        }
                    }
                }
            }
        }
    }

    post {
        success {
            script {
                echo 'Build succeeded, Jira issues updated.'
            }
        }
        failure {
            script {
                def issueKeys = sh(
                    script: "git log -1 --pretty=%B | grep -oE '[A-Z]+-[0-9]+' || true",
                    returnStdout: true
                ).trim().split("\\n")
                for (key in issueKeys) {
                    if (key) {
                        jiraComment issueKey: key, body: "Build ${env.BUILD_NUMBER} FAILED. Check ${env.BUILD_URL}console"
                    }
                }
            }
        }
    }
}

Transitioning Jira Issues Automatically

Beyond comments, you can move tickets through their workflow. For example, transitioning an issue to “Done” after a successful production deploy:

stage('Transition Jira Issue') {
    steps {
        script {
            jiraTransitionIssue idOrKey: 'PROJ-123', input: [
                transition: [id: '31']  // ID for "Done" transition, found via Jira workflow settings
            ]
        }
    }
}

You’ll need to look up the numeric transition ID for your Jira project’s workflow, which you can get by querying GET /rest/api/2/issue/{issueIdOrKey}/transitions against the Jira REST API.

Enforcing Commit Message Standards

This integration only works well if commit messages actually contain Jira keys. I strongly recommend enforcing this with a Git commit-msg hook or a branch naming convention like feature/PROJ-123-add-login, and extracting the key from the branch name in your Jenkinsfile as a fallback:

def issueKey = (env.BRANCH_NAME =~ /[A-Z]+-[0-9]+/)[0]

Integrating with the Wider Toolchain

In a typical setup, Jira integration sits alongside:

Monitoring and Troubleshooting

Security Best Practices

Best Practices

FAQs

Does this work with Jira Server, Data Center, and Cloud equally? Mostly yes, though authentication differs – Cloud uses API tokens, Server/Data Center typically uses basic auth or PATs depending on version.

Can Jenkins create new Jira issues automatically, e.g., for failed builds? Yes, using the jiraNewIssue pipeline step or the REST API directly via httpRequest.

What if a commit references a Jira key from a different project? The plugin doesn’t care which project the key belongs to as long as your Jira credential has permission there.

Can I attach build artifacts directly to a Jira issue? Yes, using jiraAddAttachment in combination with your archived build artifact path.

Is this integration one-way (Jenkins to Jira) or can Jira trigger Jenkins builds? It can be two-way – Jira Automation rules can call a Jenkins webhook to trigger a build when an issue transitions to a certain status.

Summary

Connecting Jenkins to Jira turns your CI/CD pipeline into a source of truth that product managers and QA can actually see without touching Jenkins. Start with the Jira Plugin and a scoped API token, wire up automatic comments based on commit message keys, then layer in issue transitions for meaningful lifecycle events. The result is a pipeline that doesn’t just build and deploy code, but also keeps your entire team’s project tracker honest and up to date.

References

Exit mobile version