Get active Jira sprint name from CLI

When you do some CI/CD jobs you might want to mark some builds with name of the current (active) Jira sprint.

We have a dozen components in the project with dedicated Jira projects and sprint names are like “Backend sprint 12”, so you probably don’t want to add useless information to the build and need only number to identify build.

Jira has a nice REST, so you can get what you want in a very simple way:

#!/bin/bash

# This one is to be executed once to figure out rapidBoardId
#curl -u kagarlickij:Password  -X GET -H "Content-Type: application/json" 'https://kagarlickij.atlassian.net/rest/greenhopper/1.0/rapidviews/list'

curl -u kagarlickij:Password -X GET -H "Content-Type: application/json" \
'https://taqneen.kagarlickij.net/rest/greenhopper/1.0/sprintquery/17?includeFutureSprints=true&includeHistoricSprints=false' \
| /usr/local/bin/jq '.sprints[] | select(.name | contains("PAC")) | select(.state == "ACTIVE") | .name' | sed 's/[^0-9]*//g' > currentSprint.txt

echo "Current Sprint number in Jira is $(cat currentSprint.txt)" 

And you can cat currentSprint.txt from WORKSPACE in any further build step:

I hope this info will be useful to you, and if you need any help feel free to use contact from on the main page.