如何读取JIRA REST API的响应

问题描述 投票:0回答:1

使用Atlassian文档,我可以使用curl命令创建新的JIRA票证。我想了解如何将此命令的响应读入变量?本质上,我想将JIRA票证ID存储到可以在其他脚本中使用的变量中。

参考链接:https://developer.atlassian.com/server/jira/platform/jira-rest-api-examples/

_ SAMPLE_CODE _

curl -D- -u charlie:charlie -X POST --data '{
    "fields": {
               "project":{
                  "key": "TEST"
               },
               "summary": "REST ye merry gentlemen.",
               "description": "Creating of an issue using project keys and issue type names using the REST API",
               "issuetype": {
                  "name": "Bug"
               }
            }
    }' -H "Content-Type: application/json" http://localhost:8080/rest/api/2/issue/

_ SAMPLE_RESPONSE _

{
    "id":"39000",
    "key":"TEST-101",
    "self":"http://localhost:8080/rest/api/2/issue/39000"
}

从上面的日志中,我想了解如何从响应(本质上为stdout)到变量中获取“键”(即JIRA编号或JIRA ID)。

bash shell jira jira-rest-api atlassian-plugin-sdk
1个回答
0
投票

您可以使用jq命令行工具从json提取值:

#!/bin/bash


key=$(curl -s -u charlie:charlie -X POST --data '{
"fields": {
           "project":{
              "key": "TEST"
           },
           "summary": "REST ye merry gentlemen.",
           "description": "Creating of an issue using project keys and issue type names using the REST API",
           "issuetype": {
              "name": "Bug"
           }
        }
}' -H "Content-Type: application/json" http://localhost:8080/rest/api/2/issue/|jq -r .key)

echo "key: $key"
© www.soinside.com 2019 - 2024. All rights reserved.