我们正在尝试从Jira REST API创建Jira票证。我们正在从文件中读取数据,并且正在尝试将其内容传递给Jira中的description字段。我们的文件包含多行,因此无法正常工作。
我们怀疑由于描述字段中有多行而无法正常工作。
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]"]}+
答案 0 :(得分:1)
是的,这是因为多行描述字段;这使JSON无效。在调试模式下构造的cURL命令中,以https://jsonlint.com/输入JSON,您将看到最终JSON中存在一些错误。您可能必须用“ \ n”替换换行符。
此accepted post中对此进行了详细说明。