如何使用jira api获取sprint的开始和结束日期?

时间:2016-05-25 06:48:31

标签: jira-rest-api

3 个答案:

答案 0 :(得分:0)

假设您是最新版本的JIRA和JIRA软件,您可以使用JIRA Agile REST API's

有趣的REST API资源是:

Get Issue:GET /rest/agile/1.0/issue/{issueIdOrKey}
此资源的输出还将包括敏捷字段和sprint名称及其id,例如:

...
"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} 此资源的输出包括sprint开始和结束日期,例如:

{
    "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
}

文档还可能包含其他有用的资源。

答案 1 :(得分:0)

要从活动的sprint获取日期:

url = 'https://www.example.com/rest/agile/1.0/board/{rapidViewId}/sprint?state=active'

并关闭:

url = 'https://www.example.com/rest/agile/1.0/board/{rapidViewId}/sprint?state=closed'

您也可以使用它来获取有关将来的sprint的信息(只需将“ closed”更改为“ future”),但请记住,将来的sprint没有日期,但是您可以获取名称和sprintID。

答案 2 :(得分:0)

不确定JIRA为什么不提供一个非常简单的Rest Endpoint来仅吐出所有sprint信息。为什么我必须处理board / boardID才能在该板上找到冲刺,为什么我必须遍历所有冲刺。

我是管理员用户,但仍然遇到一些冲刺#给了我Sprint does not exist

无论如何,这是一个变通方法脚本。

#!/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"

在此文件上运行cat命令将为您提供类似的信息:

 1,Trumpy Trump,2019-01-09,2019-01-23
 2,Magical Modi,2019-01-18,2019-02-01

您可以在上面的脚本中添加一行,通过具有标题行Sprint_Name,Sprint_Start_Date,Sprint_End_Date来将其用作纯CSV文件,由于我的用例只是使用该文件作为参考文件。

有关日期的相关文章:BASH: How to find no. of days (considering only "Network / Business Days") between two dates (i.e. exclude weekends Saturday/Sunday)