使用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)。
您可以使用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"