Save your time with this Github+Jira automation 🚀

Konstantinos Nikoloutsos
4 min readFeb 26, 2023

“Special thanks to my colleague and friend Βάιος-Παναγιώτης Τσιτσώνης | St4B for giving me the idea and a basic implementation“

JIRA is among the world’s most popular project management and workflow management tools for agile software development teams and tech startups.

We developers use Github for our everyday work and often open issues when we find a problem or want to propose an enhancement. 🐙

On planning sessions before adding this automation, in Blueground, the moment we decided as a team to implement a Github issue we had to manually go to JIRA and create a ticket. We do that because other team members can see what we are working on in the JIRA platform.

Imagine having to manually create many Github Issues to JIRA tickets.🤔
What if I told you that you are waisting your time on planning sessions ⏰

We developers need to focus more on actual planning than doing “data entry” 😆

What if there was a better way?
Yes, we can automate this 🥳, and I will show you how step by step!

By the end of this article wou will achieve this 💙

By the end of this article, you will have:

✅ Saved your team’s precious time on planning ⏲
✅ Your teamates will know which Github issues are tracked by jira. (since issues will be marked with jira label) 📓
✅ Made your first github action automation (if not already) 🎉

Let’s start — Create a Github action

  • Open your repository in the root level and create a folder named .github .
  • Inside this folder create another one named workflows .
  • Then create a github action yaml with whatever name you wish.(I used make_jira_ticket.yml)
  • Now put the following yaml inside it 👇.
name: "Open Jira ticket"
on:
issues:
types:
- labeled

jobs:
build:
runs-on: ubuntu-latest
if: github.event.label.name == 'jira'
name: Open Jira ticket
steps:
- name: Open ticket
run: |
curl \
-D- \
--user '${{ secrets.JIRA_USER_EMAIL }}:${{ secrets.JIRA_API_TOKEN }}' \
-X POST \
--data '{
"fields":{
"project":{
"key":"GX"
},
"summary":"iOS - ${{ github.event.issue.title }}",
"description":{
"type":"doc",
"version":1,
"content":[
{
"type":"paragraph",
"content":[
{
"text":"https://github.com/bluegroundltd/guest-app-ios/issues/${{ github.event.issue.number }}",
"type":"text",
"marks":[
{
"type":"link",
"attrs": {
"href": "https://github.com/bluegroundltd/guest-app-ios/issues/${{ github.event.issue.number }}",
"title": "Issue-${{ github.event.issue.number }}"
}
}
]
}
]
}
]
},
"issuetype":{
"name":"Task"
},
"assignee": {
"id": null
}
}
}' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
"https://devblueground.atlassian.net/rest/api/3/issue" \
-o response.json
- name: Comment on issue
run: |
jira_key=$(cat response.json | jq -r ".key")
gh issue comment $ISSUE --body "Hey beegee @${{ github.actor }} 👋,
a [JIRA ticket](https://devblueground.atlassian.net/browse/$jira_key) was created.
<p align="right"> Generated by <a href="https://github.com/bluegroundltd/guest-app-ios/blob/develop/.github/workflows/make_jira_ticket.yml">this workflow</a> 💙 </p>"
env:
GITHUB_TOKEN: ${{ secrets.REPO_ACCESS_TOKEN }}
ISSUE: ${{ github.event.issue.html_url }}

In high level, this action will be triggered only when a jira label is added to an issue. This action first make a call to JIRA Rest API to create the ticket and lastly with the help of github CLI it makes a comment on the issue and exposes the Jira URL.

Finishing up the action & adjust to your needs

Great job you’re almost there 👏

You’ve made a github-action ready to be used. But does it actually work? On new label jira is triggered but not working yet. That’s because the action expects as to set some GitHub secrets and configure it to our needs.

  1. You have to create a JIRA token. Follow this guide.
    Once created make a github repository secret named JIRA_API_TOKEN
    Also make another secret with the associated email you created the above token and save it in JIRA_USER_EMAIL
  2. Last but not least make a github personal access token and make a secret with name REPO_ACCESS_TOKEN . This is needed so that when Jira ticket is created to report the URL back into the issue as a comment.

3. Make sure in the github action you have used the correct jira base API URL. In my company that is `https://devblueground.atlassian.net. Your company may have a different hosting domain. (You can easily find the domain by taking a look at your browser’s URL)

4. Now you have to replace with your JIRA project name.
Your JIRA may have more than 1 projects. Go back to the action and replace the `fields.project.key` with yours. (in our case was GX)

Here is how to find your project name in your JIRA

Github Secrets are encrypted variables that you create in an organization, repository, or repository environment. The secrets that you create are available to use in GitHub Actions workflows.
Secrets in github actions are accessed under ${{ secrets.XXX }}

5. If you want to customize even more take a look at what JIRA API offers.

Conngratulations — your have saved your team’s time 🎉

Now you can add label named jira on your issue and it will make a JIRA ticket for you.

The end result 👆

Now you can copy-paste this github action across all your repositories.

I hope you liked this automation as much as I did. If you have more automations in mind that can save our time don’t hesitate to share.
I would be really curious to take a look at them 💙

If you liked this article don’t forget to leave a 👏
See you in the next article 👋

--

--