【问题标题】:Unable to create Jira ticket using Jira REST API because description filed is having multi line comments无法使用 Jira REST API 创建 Jira 票证,因为描述文件包含多行注释
【发布时间】:2018-08-08 10:34:36
【问题描述】:

我们正在尝试从 Jira REST API 创建 Jira 票证。我们正在从文件中读取数据,并且我们试图将这些内容传递给 Jira 中的描述字段。我们的文件包含多行,因此它不起作用。

我们怀疑这不起作用,因为描述字段中有多行。

curl -D- -k -u user:pwd -X POST --data '{"fields": {"project": {"key": "KOSPN"},"summary": "NOCAutomation-EnvName-Issue","description": "'"$(cat /root/ZK/lle/final.txt)"'","issuetype": {"name": "'$Issuetype'"},"customfield_16103": {"value": "'$env'"},"customfield_13700": {"value": "'$level'"},"customfield_16102": {"value": "'$Domain'"},"customfield_11506": {"value": "'$release'"},"customfield_11805": {"value": "'"$RequestType"'"},"customfield_12300": {"value": "'"$project"'"},"customfield_21305": {"value": "'$No'"},"customfield_11804": [{"value": "'$Component'"}]}}' -H "Content-Type: application/json" https://jiradc.test.com:8443/rest/api/2/issue

/root/ZK/lle/final.txt 的内容,用作描述字段的输入

QA02 cncservice ACM_SERVICE_HOST actual value (10.208.4.18) is not matching with expected value (10.208.9.21)
QA02 cncservice SNB_SERVICE_HOST actual value (10.208.99.9) is not matching with expected value (10.208.9.12)
QA02 cncservice XYZ_SERVICE_HOST actual value (10.208.4.118) is not matching with expected value (10.208.9.3)

错误: 当我在调试模式下执行脚本时,下面是为 CURL 命令构造的:

curl -D- -k -u user:passwd -X POST --data '{"fields": {"project": {"key": "KOSPN"},"summary": "NOCAutomation-EnvName-Issue","description": "QA02 cncservice ACM_SERVICE_HOST actual value (10.208.4.18) is not matching with expected value (10.208.9.21)
QA02 cncservice SNB_SERVICE_HOST actual value (10.208.99.9) is not matching with expected value (10.208.9.12)
QA02 cncservice ACM_SERVICE_HOST actual value (10.208.4.18) is not matching with expected value (10.208.9.21)","issuetype": {"name": "Task"},"customfield_16103": {"value": "QA02"},"customfield_13700": {"value": "L1"},"customfield_16102": {"value": "ACT"},"customfield_11506": {"value": "Backlog"},"customfield_11805": {"value": "Environment Issues"},"customfield_12300": {"value": "2018 VGC"},"customfield_21305": {"value": "Yes"},"customfield_11804": [{"value": "accservices"}]}}' -H 'Content-Type: application/json' https://jiradc.test.com:8443/rest/api/2/issue

回复是:

HTTP/1.1 400
X-AREQUESTID: 327x44020628x4
X-ANODEID: pl001367
X-XSS-Protection: 1; mode=block
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
Content-Security-Policy: frame-ancestors 'self'
X-ASEN: SEN-4259792
Set-Cookie: JSESSIONID=30FA54033D0AA6EFA9716EA5C9E69AED;path=/;Secure;HttpOnly
X-Seraph-LoginReason: OK
Set-Cookie: atlassian.xsrf.token=BOOQ-GGIW-E4RQ-BKG0|119aa3a9b6cd1c35ddacddaf0f8dad1cfd798c26|lin;path=/;Secure
X-ASESSIONID: 1ez4fp1
X-AUSERNAME: TKMADNI
Cache-Control: no-cache, no-store, no-transform
Content-Type: application/json;charset=UTF-8
Transfer-Encoding: chunked
Date: Wed, 08 Aug 2018 10:27:21 GMT
Connection: close

{"errorMessages":["Illegal unquoted character ((CTRL-CHAR, code 10)): has to be escaped using backslash to be included in string value\n at [Source: org.apache.catalina.connector.CoyoteInputStream@64531914; line: 1, column: 208]"]}+

【问题讨论】:

  • 数据文件只有一行不返回是否有效?
  • 是的,一行就可以了

标签: shell curl jira cat jira-rest-api


【解决方案1】:

是的,这是因为多行描述字段;这使 JSON 无效。在调试模式下构造的 cURL 命令中,在https://jsonlint.com/ 中输入 JSON,您将看到最终 JSON 中有一些错误。您可能必须将换行符替换为“\n”。

这在accepted post中有更详细的解释。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-08-27
    • 2022-06-13
    • 2015-08-28
    • 1970-01-01
    • 2022-10-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多