Create your FREE Codefresh Account!

Create your FREE Codefresh Account!

Create your FREE Codefresh Account with...

Automate Jira Updates in your Codefresh CI/CD Pipelines

Containers | September 18, 2017

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.

jira-cli

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:

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:

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

About 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. When not evangelising for Codefresh, he's deeply involved with technical training and public speaking.

Reader Interactions

Enjoy this article? Don't forget to share.

Comments

Your email address will not be published. Required fields are marked *

Follow me on Twitter