需求
大家都说无欲则刚啊,️需求就没有这么多麻烦事儿。
一个内部需求 -> 运用bash来批量更新工单
- 更新release版别信息
- 更新部件component信息
- 更新工单状况信息
- 留言(️选)
乍一看这个需求如同很简单啊,一个request恳求不就解决战斗了么
往往越简单的事情️能越杂乱,要不也没有这个踩坑日记
运用bulk批量更新
翻开jira api 官方文档一看,感觉和刚接到需求一样,这玩意太简单了啊,官方描绘 :
create or edit issues, individually or in bulk.
这不便是单个或者批量创建/更新issue的意思么,赶快用起来吧
curl --request POST \
--url 'https://your-domain.atlassian.net/rest/api/2/issue/bulk' \
--user 'email@example.com:<api_token>' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data '{
"issueUpdates":[ {
"fields": {
"assignee": {
"id": "5b109f2e9729b51b54dc274d" },
"components": [ { "id": "10000" } ],
"customfield_10000": "09/Jun/19",
"customfield_20000": "06/Jul/19 3:25 PM", "customfield_30000": [ "10000", "10002" ], "customfield_40000": "Occurs on all orders", "customfield_50000": "Could impact day-to-day work.", "customfield_60000": "jira-software-users", "customfield_70000": [ "jira-administrators", "jira-software-users" ],
"customfield_80000": { "value": "red" },
"description": "Order entry fails when selecting supplier.",
"duedate": "2019-03-11",
"environment": "UAT",
"fixVersions": [ { "id": "10001" } ],
"issuetype": { "id": "10000" },
"labels": [ "bugfix", "blitz_test" ],
"parent": { "key": "PROJ-123" },
"priority": { "id": "20000" },
"project": { "id": "10000" },
"reporter": { "id": "5b10a2844c20165700ede21g" }, "security": { "id": "10000" },
"summary": "Main order flow broken",
"timetracking": { "originalEstimate": "10", "remainingEstimate": "5" },
"versions": [ { "id": "10000" } ] },
"update": { "worklog": [ { "add": { "started": "2019-07-05T11:05:00.000+0000", "timeSpent": "60m" } } ] } }, { "fields": { "assignee": { "id": "5b109f2e9729b51b54dc274d" }, "components": [ { "id": "10000" } ], "customfield_10000": "09/Jun/19", "customfield_20000": "06/Jul/19 3:25 PM", "customfield_30000": [ "10000", "10002" ], "customfield_40000": "Occurs on all orders", "customfield_50000": "Could impact day-to-day work.", "customfield_60000": "jira-software-users", "customfield_70000": [ "jira-administrators", "jira-software-users" ], "customfield_80000": { "value": "red" }, "description": "Order remains pending after approved.", "duedate": "2019-04-16", "environment": "UAT", "fixVersions": [ { "id": "10001" } ], "issuetype": { "id": "10000" }, "labels": [ "new_release" ], "parent": { "id": "10034" }, "priority": { "id": "20000" }, "project": { "id": "1000" }, "reporter": { "id": "5b10a2844c20165700ede21g" }, "security": { "id": "10000" }, "summary": "Order stuck in pending", "timetracking": { "originalEstimate": "15", "remainingEstimate": "5" }, "versions": [ { "id": "10000" } ] }, "update": {} } ] }'
这个rest/api/2/issue/bulk
只能用来批量创建,底子就不能满足咱们的需求,无法批量更新工单信息 -> 直接放弃了
运用循环更新工单
已然bulk不能用,那只能用起传统的一招鲜了,来个循环,挨个工单更新不就好了么, 还是太年青啊, jira 能让你不多花点钱么,你便是用循环还是无法在一个api恳求里完成✅上面的需求, 让咱们为啥
curl --request PUT \
--url 'https://your-domain.atlassian.net/rest/api/2/issue/{issueIdOrKey}' \
--user 'email@example.com:<api_token>' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data '{"update": {
"components": [ { "add": "component example" } ],
"fixVersions": [ { "add": "Test-1.2.89" }]} }'
这个 rest/api/2/issue/{issueIdOrKey}
API, 只能更新工单部分信息,并不能更改工单的状况。 这里⚠️要运用PUT
方法,成功之后HTTP状况码为204
body为️
如何更新工单状况 Status呢?
要把一个工单状况改为 “Fixed”,还得每个工单再调一遍这个新的API
curl --request POST \
--url 'https://your-domain.atlassian.net/rest/api/2/issue/{issueIdOrKey}/transitions' \
--user 'email@example.com:<api_token>' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data '{ "transition": { "id": "5" },
"update": {
"comment": [ { "add": { "body": "Bug has been fixed." } } ]
}
}'
用上rest/api/2/issue/{issueIdOrKey}/transitions
咱们就可以更新工单状况了,同时在工单下留下评论。
这个API也是成功后不回来body,直接204状况
已然它长得和上一步的那个API那么像,咱们能不能用它来同时更新工单版别还有组件信息呢?
答案是 :不能
不知道出于什么原因JIRA真的太了, 工单不能通过API批量更新,更新每个工单信息时状况要单独更改。
这可和UI版别的bulk不一样,也许这便是Cloud的奥妙吧
- 运用付钱,不运用不付钱
- 功能差异化,API不能代替UI产品
- 用API️以完成✅许多需求,可是调用API的成本是按条算的
参阅官方文档链接
现在需求的坑是填完了,JIRA API想用好你真的不容易 ☹️