同事的專案因為時間長,累積超過上千個Jira issues,每到了專案會議前要整理issues狀態作統計,就會收到客戶對於下載上限1,000筆限制的抱怨,來幫DevOps Team解題。
解題方式收集到二種:
- 手動下載(修改下載網址)
- 寫小工具使用Atlassian.SDK下載
手動下載
最快最簡單的Workaround就是修改下載網址:
(1)在Issue navigator確認好JQL條件後,按下下載圖示的按鈕
(2)滑鼠游標移動到下載的方式,然後按下滑鼠右鍵,複製下載網址。
這邊我們複製出來的網址列如下:
https://<INSTANCE NAME>/sr/jira.issueviews:searchrequest-csv-current-fields/temp/SearchRequest.csv?jqlQuery=project+%3D+<PROJ>+ORDER+BY+created+DESC&tempMax=1000
- *<INSTANCE NAME>置換成jira instance name
- *<PROJECT>置換成專案名稱
(3)下載前1,000筆
打開瀏覽器,輸入網址
https://<instance name>atlassian.net/sr/jira.issueviews:searchrequest-csv-all-fields/temp/SearchRequest.csv?jqlQuery=project+%3D+U+ORDER+BY+created+DESC&tempMax=1000
(4)下載1,000-2,000筆(加上&pager/start=1000,依此類推2000,3000)
https://<instance name>atlassian.net/sr/jira.issueviews:searchrequest-csv-all-fields/temp/SearchRequest.csv?jqlQuery=project+%3D+U+ORDER+BY+created+DESC&tempMax=1000&pager/start=1000
(5)將兩個csv檔案合併。
如果還不滿意Atlassian官方 Knowledge Base的解答,來自幹一個工具。
寫小工具使用Atlassian.SDK下載
(1)打開地表最強IDE: Visual Studio,並且新增一個主控台專案JiraExportConsole(.NET Framework > = 4.5.2)
(2)透過Nuget封裝管理員安裝Atlassian.SDK
(3)Program.cs程式碼
使用SDK每次最多只能取回100筆 Issues,我們需要串接多次的查詢結果。
using Atlassian.Jira;
using System;
using System.Collections.Generic;
using System.Linq;
namespace JiraExportConsole
{
internal class Program
{
private static void Main(string[] args)
{
JiraRestClientSettings jiraRestClientSettings = new JiraRestClientSettings();
jiraRestClientSettings.EnableRequestTrace = true;
var jira = Jira.CreateRestClient("https://<INSTANCE>.atlassian.net",
"帳號", "密碼", jiraRestClientSettings);
int i = 1;
List<Issue> allissues = GetJiraIssue(jira, i, "專案名稱");
while (1 == 1)
{
i++;
var issues = GetJiraIssue(jira, i, "專案名稱");
allissues = UnionJiraIssue(allissues, issues);
if (issues.Count() < 100)
{
break;
}
}
Console.WriteLine($"總共{allissues.Count}issues");
Console.ReadKey();
}
static List<Issue> GetJiraIssue(Jira jira, int page, string projName)
{
var issues = (from i in jira.Issues.Queryable
where i.Project == projName
orderby i.Created descending
select i).Skip((page - 1) * 100).Take(100).ToList();
return issues;
}
static List<Issue> UnionJiraIssue(List<Issue> issues1, List<Issue> issues2)
{
List<Issue> union = issues1.Union(issues2).ToList();
return union;
}
}
}
(4)按下F5執行,顯示總共Issues數目:1,564
小結
- 懷念TFS WorkItem,程式碼簽入時還能自動選。
- 目前支援的欄位:
希望飛機幫同事帶走所有的壞issues
2018/07 舊宗路(不過..這架是降落的..)
參考
JIRA Knowledge Base Export More than 1000 Issues to Excel from Issue Navigator in JIRA Cloud
Atlassian.Net SDK / JQL Support