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:
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' steps: GetJiraID: title: Get Jira ID image: alpine:latest commands: - echo JIRAID=$(echo "${{CF_COMMIT_MESSAGE}}" |sed -e 's/([A-Z]*-[0-9]*).*/1/') > ${{CF_VOLUME_PATH}}/env_vars_to_export BuildingDockerImage: title: Building Docker Image type: build image_name: otomato/bringon working_directory: ./ dockerfile: Dockerfile tag: '${{CF_SHORT_REVISION}}' UpdatingJira: title: Update Jira Issue image: otomato/jira-cli:alpine commands: - 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} when: condition: all: 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:
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.
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!