【问题标题】:How to get start and end dates of a sprint using jira api?如何使用 jira api 获取 sprint 的开始和结束日期?
【发布时间】:2023-03-07 14:57:01
【问题描述】:

【问题讨论】:

    标签: jira-rest-api


    【解决方案1】:

    从活动冲刺中获取日期:

    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'
    

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

    【讨论】:

      【解决方案2】:

      假设您是 JIRA 和 JIRA Software 的最新版本,您可以使用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
      }
      

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

      【讨论】:

        【解决方案3】:

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

        我是管理员用户,但仍然会遇到一些 sprint # 给我,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
        

        在哪里,您可以在上面的脚本中添加一行,通过标题行将其用作纯 CSV 文件,即 Sprint_Name,Sprint_Start_Date,Sprint_End_Date,我只是没有这样做,因为我的用例是只使用这个文件作为参考文件。

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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2023-03-04
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多