JIRA on the CLI
Small discovery I’ve made a while ago: jira. It’s a small go binary that can do about everything you want on JIRA.
Let’s first log into our JIRA instance:
mkdir ~/.jira.d/
echo 'endpoint: jira.company.com' > ~/.jira.d/config.yml
jira login
And then create our first issue!
jira create -p PROJ -i Task -b
This command will create a Task in PROJECT and then open it in your browser. Upon creation, it’ll fire up your $EDITOR
for you to edit the fields you need. You could also change this editor in the configuration with editor: vim
.
That’s pretty basic, let’s say you want to start working on PROJ-42 and comment something:
jira take PROJ-42
jira progress PROJ-42
As you go you need to add a comment to the task:
jira comment PROJ-42 # will open $EDITOR for you to comment
And finally, resolve it:
jira resolve PROJ-42
jira close PROJ-42
One thing I use often is browse
, this command will open the corresponding ticket in your browser, rather than opening JIRA, type the issue key and hit enter in JIRA:
jira browse PROJ-42
This is still pretty basic, one thing I love with this tool is the ability to write custom workflows. See this configuration:
custom-commands:
- name: mine
help: display issues assigned to me
script: |-
if [ -n "$JIRA_PROJECT" ]; then
# if `project: ...` configured just list the issues for current project
{{jira}} list --template table --query "resolution = unresolved and assignee=currentuser() and project = $JIRA_PROJECT ORDER BY priority asc, created"
else
# otherwise list issues for all project
{{jira}} list --template table --query "resolution = unresolved and assignee=currentuser() ORDER BY priority asc, created"
fi
- name: recent-proj
help: display PROJs created within the past 4 days
script: |
jira list -q "project = PROJ AND created >= -4d" -t table
- name: my-updated-2d
help: display tickets updated by the current user within the past 2 days
script: |
jira list -q 'issueFunction in commented("by currentUser() after -2d") or (status changed BY currentuser() after -2d) or (created >= -2d and creator = currentuser() ) or (assignee changed by currentuser() after -2d)'%
As you can see, these custom commands are only calling jira itself using JQL. You can use these commands as follows:
jira mine
jira recent-proj
jira my-updated-2d
One last example are slightly more complicated custom commands with arguments. I have a workflow where I need to create 2 tickets for the same issue and link them as blocking:
custom-commands:
- name: failed-disk
help: create a PROJ and a MID ticket for a failed disk
options:
- name: host
short: h
required: true
- name: disk
short: d
required: true
- name: disk_serial
short: s
required: true
- name: host_serial
required: true
script: |-
DESCRIPTION="
The following disk on {{options.host}} {{options.host_serial}} has failed:
- {{options.disk}} (serial {{options.disk_serial}})
"
proj=$(jira create -p PROJ -i "Task" -o summary="{{options.host}}: failed disk" -o components=disk -o description="$DESCRIPTION" --noedit)
echo $proj
mid=$(jira create -p MID -i "Task" -o summary="{{options.host}}: failed disk" -o description="$DESCRIPTION" --noedit)
echo $mid
jira issuelink -b $(echo $proj | cut -d" " -f2) Blockers $(echo $mid | cut -d" " -f2)
Now, instead of going crazy clicking in JIRA for 10 minutes, I can just fire the following command and be done with it:
jira failed-disk -h $hostname -d /dev/sda -s DJHWO72DK --host_serial
As much as I dislike JIRA, it’s not going away anytime soon and tools like this one are helping not going crazy trying to deal with the UX. There is another one that I haven’t tried yet: jiracli. Let me know if you did!
– This is day 2/100 of #100DaysToOffLoad!