Create your FREE Codefresh account and start making pipelines fast. Create Account

Automate Jira Updates in your Codefresh CI/CD Pipelines

3 min read

Jira Everywhere

Atlassian Jira has become the de facto standard for managing complex workflows of enterprise software delivery teams. JIRA, Confluence, and Bitbucket, combine to provide an end-to-end information hub across the entire company. This is the place where we want all our work to be visible, actionable and traceable.

It is very easy to integrate Jira into Bitbucket. A developer simply needs to supply a Jira issue key as a part of their commit message. Something like: “CFD-1234 – Support Docker healthchecks”. The built-in integration automatically pulls this information from Bitbucket and updates the relevant issue with commit information.

We Want to see Artifacts

With the modern reality of continuous integration and delivery – each commit results in a given build, and each successful build results in a build artifact. In our case, this would be a Docker image.

We can get more visibility in JIRA by linking our image to the work items. Let’s start by updating our JIRA issue right from the Codefresh CI/CD pipeline.


IIn order to do this, we will use the open source python-based jira-cli utility. We’ve wrapped it in a lightweight alpine-based Docker image found here.

You can use the one we’ve built or you can roll your own with the following Dockerfile:

FROM python:2-alpine
RUN apk add -U gcc musl-dev linux-headers openssl-dev libffi-dev && pip install jira-cli

The resulting Docker image will be our tool for updating Jira today.

Codefresh Flow

This is the codefresh.yml file we will be using for building our flow:

version: '1.0'
    title: Get Jira ID
    image: alpine:latest
      - echo JIRAID=$(echo "${{CF_COMMIT_MESSAGE}}" |sed -e 's/\([A-Z]*-[0-9]*\).*/\1/') > ${{CF_VOLUME_PATH}}/env_vars_to_export
    title: Building Docker Image
    type: build
    image_name: otomato/bringon
    working_directory: ./
    dockerfile: Dockerfile
    tag: '${{CF_SHORT_REVISION}}'
    title: Update Jira Issue
    image: otomato/jira-cli:alpine
      - yes n | jira-cli update ${JIRAID} --comment 'New docker image otomato/bringon:${{CF_SHORT_REVISION}}. Build log is here ${{CF_BUILD_URL}}' --jira-url ${JIRA_URL} -u ${JIRA_USR} -p ${JIRA_PWD}
              JiraIdFound: 'match("${JIRAID}", "[A-Z]+-[0-9]+", true)'

Let’s see what we are doing here.
In the first step (named GetJiraID) we’re parsing the git commit message, by searching for the Jira issue key. We’re doing this inside a basic alpine image with the help of echo and sed utilities. Note that every variable written to ${{CF_VOLUME_PATH}}/env_vars_to_export in the format of “VARIABLE=VALUE” will become available in all subsequent pipeline steps. Then we’re defining the JIRAID variable to hold the issue key value.

Also note that if the developer isn’t compliant enough to include the issue key in their commit message, then JIRAID will hold the full string of the message.
We check for this in the last step’s ‘when’ condition so as not to try updating Jira if no issue key was provided. We then build the Docker image for our service and tag it with the abbreviated 7-character git revision hash. If the image build is successful – it’s time to update Jira with our build information.

Talking to Jira

This is where we use our jira-cli:alpine container. Inside it we execute the cli tool with update sub-command.This will add a comment on the relevant issue providing image:tag name and Codefresh build url information. Note that we’re using the JRA_URL, JIRA_USR and JIRA_PWD variables to connect to the Jira instance. These variables are defined in our Codefresh pipeline definition in this approach:

jira conection details in Codefresh pipeline variables

Again, we’re using a conditional expression to make sure that JIRAID retrieved in the first step actually matches the issue key pattern. You can get more information on Codefresh execution condition syntax here.

Jra issue updated with docker build information

Now we can easily access all Docker images and build logs straight from the issue description.
That was easy, wasn’t it?

What’s Next?

IIn the follow-up post, we will learn how to use the same technique to retrieve Jira issue details and populate the metadata tags of our images.

Meanwhile – please share your feedback on the described use cases. Let us know if you find it to be a good fit with your CI/CD flow!

Anton Weiss

Ant(on) Weiss is a DevOps Evangelist and Enabler. He's been architecting software delivery processes at large and small companies for the last 15 years. Today he's the CEO and Principal Consultant at Otomato and deeply involved with technical training and public speaking.

2 responses to “Automate Jira Updates in your Codefresh CI/CD Pipelines

  1. Hi Anton! Thanks for the post. Its help. Is there a way to create a Jira issue not just update the description from codefresh in case the test fails. Thanks !

    1. Ant Weiss says:

      Hi Rabia,
      Basically anything that’s possible with jira-cli can be done here. jira-cli new allows creating new issues. For more details – please read the docs:
      Note – the docker image mentioned in the article was created 3 years ago so the version is quite outdated. I’d recommend wrapping your own with the last version of jira-cli to get all the up-to-date functionality

Leave a Reply

* All fields are required. Your email address will not be published.