Below url is giving all the information except start and end dates of a sprint .
3 Answers
To get dates from active sprint:
url = 'https://www.example.com/rest/agile/1.0/board/{rapidViewId}/sprint?state=active'
And closed:
url = 'https://www.example.com/rest/agile/1.0/board/{rapidViewId}/sprint?state=closed'
You could use the same also to get information about future sprint (just change "closed" to "future") but keep in mind that future sprints doesn't have dates, but you can get name and sprintID.
Assuming you're a recent version of JIRA and JIRA Software, you can use the JIRA Agile REST API's.
Interesting REST API resources are:
Get Issue: GET /rest/agile/1.0/issue/{issueIdOrKey}
The output of this resource will also include the agile fields and the sprint name and its id, e.g.:
...
"sprint": {
"id": 37,
"self": "http://www.example.com/jira/rest/agile/1.0/sprint/13",
"state": "future",
"name": "sprint 2"
},
...
Get Sprint: GET /rest/agile/1.0/sprint/{sprintId} The output of this resource include the sprint start and end dates, e.g.:
{
"id": 37,
"self": "http://www.example.com/jira/rest/agile/1.0/sprint/23",
"state": "closed",
"name": "sprint 1",
"startDate": "2015-04-11T15:22:00.000+10:00",
"endDate": "2015-04-20T01:22:00.000+10:00",
"completeDate": "2015-04-20T11:04:00.000+10:00",
"originBoardId": 5
}
The docs may also contain other useful resources for you.
Not sure why JIRA doesn't provide a very simple Rest Endpoint to just spit all sprints info. Why I have to deal with board/boardID to find sprints in that board, why I have to iterate over all sprints.
I'm administrator user and still hitting some of the sprint # gives me, Sprint does not exist
.
Anyways, here's a work-around script.
#!/bin/bash
JIRA_URL="http://my_jira_server:8080"
users_sprint_limit_cmd_line_arg="$1"
# First parameter passed to the script is a NUMBER (for how many sprints a user wants to iterate over.
## I know!! it's a work-around for dealing with "Sprint does not exist" and
## becasue there's no shitty direct JIRA Rest API that exist, to query JIRA server, to spit all SPRINTS with info (start/end date) in just one call.
## You can use API token (or base64 hash). I'm just going rouge here.
user="a_user_user_who_can_read_any_sprint_or_serviceuser_or_admin"
pass="D00M4u!"
## Set build number variable
b_no=${BUILD_NUMBER:="999999"}
## At the end, you'll have a Temp file will store all sprints info, Valid will contain only valid sprints.
temp_sprint_file="/tmp/all_sprints_startdates_${b_no}_temp.txt"
valid_sprint_file="/tmp/all_sprints_startdates_${b_no}.txt"
## Clean files
rm ${temp_sprint_file} ${valid_sprint_file} || true;
## Sprint counter
sprint_no=1
result="ToBeSet"
## Iterate over all sprints and find their start/stop dates.
## -- This is one-odd way to find sprint's start/end dates, but it works!!
## -- A user can pass a larger value in while condition "-lt value" via cmd line 1st param.
while [[ $sprint_no -lt ${users_sprint_limit_cmd_line_arg} ]];
do
## assumes 'jq' is installed. --OR run: sudo yum install jq
## --------------------------
result="$(curl -s -u $user:$pass -X GET -H 'Content-Type: application/json' "${JIRA_URL}/rest/agile/1.0/sprint/${sprint_no}" | \
jq | \
egrep "name|startDate|endDate" | \
cut -d'"' -f4 | \
sed "s/T[0-9][0-9]:[0-9][0-9].*$//" | \
tr '\012' ',' | \
sed "s/,$//")";
echo "${result}" >> ${temp_sprint_file}
((sprint_no++));
done
## Find valid sprints which have valid start/end dates.
## -- Just retain unique lines. Don't sort. Don't remove duplicates.
## -- Sort on 2nd column (i.e. sprint's start date) and use sort cmd "-t" option for using ',' as column separator (rather than default ' ' single space).
grep "[A-Za-z0-9],[0-9].*,[0-9]" ${temp_sprint_file} | \
sort -k 2 -t',' | uniq | cat -n | \
sed "s/^[ \t][ \t]*\([1-9][0-9]*\)[ \t][ \t]*/\1,/" > ${valid_sprint_file};
echo -e "\n\n-- Sprints and Start/End Date file is available here: ${valid_sprint_file}\n\n"
Running cat
command on this file will give you, something like:
1,Trumpy Trump,2019-01-09,2019-01-23
2,Magical Modi,2019-01-18,2019-02-01
Where, you can add a line in the above script, to use it as a pure CSV file by having a header line i.e. Sprint_Name,Sprint_Start_Date,Sprint_End_Date
, I just didn't do that as my use case was to use just this file as a reference file.
A related post regarding dates: BASH: How to find no. of days (considering only "Network / Business Days") between two dates (i.e. exclude weekends Saturday/Sunday)