Jira CI/CD Integration
Tags: jira, devops, gitlab, drone
Published: 2021-08-08 06:51:35

---
title: Jira CI/CD Integration
published: true
date: 2021-08-08 05:00:00 UTC
tags: jira, devops, gitlab, drone
canonical_url: https://rohit.page/blog/projects/jira-ci-cd-integration-for-builds-deploys/
---

Integrate your CI/CD pipeline's Build and Deployment information into the Jira Development Panel. Enable better

![Builds Panel Preview](https://raw.githubusercontent.com/rohit-gohri/jira-ci-cd-integration/main/docs/builds-panel.png)

> Only supports Jira Cloud. Does not support Jira Server (hosted)

## Prerequisites

### Generate Credentials

Generate new OAuth Credentials and copy

**See:** [https://support.atlassian.com/jira-cloud-administration/docs/integrate-with-self-hosted-tools-using-oauth/](https://support.atlassian.com/jira-cloud-administration/docs/integrate-with-self-hosted-tools-using-oauth/)

![OAuth Creds Screen](https://raw.githubusercontent.com/rohit-gohri/jira-ci-cd-integration/main/docs/oauth-creds.png)

## Use with Any CI/CD Provider

As long as your CI/CD provider supports running Docker images you may use this integration. Tested in Drone.io, Gitlab CI, and Google Cloud Run.

Docker Images are available from:

- Gitlab Container Registry: `registry.gitlab.com/rohit-gohri/jira-ci-cd-integration`
- Github Container Registry: `ghcr.io/rohit-gohri/jira-ci-cd-integration`
- Docker Hub: `boringdownload/jira-integration`

Pick whatever you want and is convenient for you.

### Set Env Vars

Configuration for the Docker image is through env vars. Read more in [options](https://github.com/rohit-gohri/jira-ci-cd-integration#options).

#### Jira-Gitlab CI/CD

[![pipeline status](https://gitlab.com/rohit-gohri/jira-ci-cd-integration/badges/v0/pipeline.svg)](https://gitlab.com/rohit-gohri/jira-ci-cd-integration/-/commits/v0)

[Add a CI/CD Variable to your project](https://docs.gitlab.com/ee/ci/variables/#add-a-cicd-variable-to-a-project) for `JIRA_CLIENT_ID` and `JIRA_CLIENT_SECRET` (remember to mask them) and then add these steps to your pipeline (we use `.post` stage so it runs last)

```
jira-integration-on-success:
  stage: .post
  when: on_success
  image: registry.gitlab.com/rohit-gohri/jira-ci-cd-integration:v0
  script: jira-integration
  variables:
    BUILD_STATE: successful
    BUILD_NAME: gitlab-pipeline
    JIRA_INSTANCE: companyname

jira-integration-on-failure:
  extends: jira-integration-on-success
  when: on_failure
  variables:
    BUILD_STATE: failure

```

#### Jira-Drone.io Example

[![Build Status](https://cloud.drone.io/api/badges/rohit-gohri/jira-ci-cd-integration/status.svg?ref=refs/tags/v0)](https://cloud.drone.io/rohit-gohri/jira-ci-cd-integration)

Add secrets for `JIRA_CLIENT_ID` and `JIRA_CLIENT_SECRET` and then add this to your pipeline:

```
steps:
  - name: jira-integration
    image: boringdownload/jira-integration:v0
    environment:
      BUILD_NAME: drone-pipeline
      JIRA_INSTANCE: companyname
      JIRA_CLIENT_ID:
        from_secret: jira_client_id
      JIRA_CLIENT_SECRET:
        from_secret: jira_client_secret

```

## Usage With Github Actions

You can also use this as a Github Action if you want to send release information to Jira.

[![test-release workflow](https://github.com/rohit-gohri/jira-ci-cd-integration/actions/workflows/test-release.yml/badge.svg)](https://github.com/rohit-gohri/jira-ci-cd-integration/actions/workflows/test-release.yml)

### Add OAuth Creds as secrets to Github

**See:** [https://docs.github.com/en/actions/reference/encrypted-secrets](https://docs.github.com/en/actions/reference/encrypted-secrets)

- Add Client ID as `JIRA_CLIENT_ID`
- Add Client Secret as `JIRA_CLIENT_SECRET`

![Github Secrets](https://raw.githubusercontent.com/rohit-gohri/jira-ci-cd-integration/main/docs/github-secrets.png)

### Update Github Workflow

#### Use in Builds Pipeline

```
- name: Jira Integration
  if: ${{ always() }}
  uses: rohit-gohri/jira-ci-cd-integration@v0
  with:
    event_type: build
    state: ${{ job.status }}
    jira_instance: companyname # Subdomain for Jira Cloud
    client_id: ${{ secrets.JIRA_CLIENT_ID }}
    client_secret: ${{ secrets.JIRA_CLIENT_SECRET }}

```

#### Use in Deployment Pipeline

```
- name: Jira Integration
  if: ${{ always() }}
  uses: rohit-gohri/jira-ci-cd-integration@v0
  with:
    event_type: deployment
    state: ${{ job.status }}
    issue: JCI-3, JCI-6 # Comma separated list of issues being deployed/released. You are expected to generate this yourself in a previous step
    jira_instance: companyname # Subdomain for Jira Cloud
    client_id: ${{ secrets.JIRA_CLIENT_ID }}
    client_secret: ${{ secrets.JIRA_CLIENT_SECRET }}

```