如何在 Jenkins Slave 的 POST 请求中正确使用变量
How do I correctly use variables in the POST request in Jenkins Slave
这是我的 POST 请求。
curl -v -k -H "Content-Type:application/json" -b /tmp/zen.cookies -X POST https://${WEB_URL}/zen-data/v2/serviceInstance -d
{"serviceInstanceNamespace":"${namespace}","serviceInstanceVersion":"1.3.5","createArguments":{"parameters":{"global.icp4Data":"true","global.pvc.pvProvisioning":"NamedStorageClass","global.filebeat.output.logstashEnabled":"false","global.filebeat.output.consoleEnabled":"true","metadata.storageClass":\"${storageclass}\","imagePullSecrets":"ownerServiceInstanceUsername":""},"transientFields":{}}
它给我这个错误:
{"code":400,"message":"parsing body body from \"\" failed, because invalid character 's' looking for beginning of value"}* Could not resolve host: serviceInstanceDisplayName; Unknown error
12:24:32 * Closing connection 1
12:24:32 curl: (6) Could not resolve host: serviceInstanceDisplayName; Unknown error
12:24:33 * Could not resolve host: serviceInstanceNamespace; Unknown error
我觉得你好像少了一个括号,试着在最后加上}
。
关于 json 格式的参数仅使用 "$storageclass"
。或类似这样的内容:
json="{\"name\": \"$name\", \"text\": \"$Text\"}"
要在 POST 命令中替换 JSON 中的变量,您需要这样做:
"'"${variableName}"'"
单引号内的双引号位于双引号内。
所以它看起来像这样:
curl -X POST www.example.com -d '{"country": "city","province":"'"${variableName}"'"}'
这是我的 POST 请求。
curl -v -k -H "Content-Type:application/json" -b /tmp/zen.cookies -X POST https://${WEB_URL}/zen-data/v2/serviceInstance -d
{"serviceInstanceNamespace":"${namespace}","serviceInstanceVersion":"1.3.5","createArguments":{"parameters":{"global.icp4Data":"true","global.pvc.pvProvisioning":"NamedStorageClass","global.filebeat.output.logstashEnabled":"false","global.filebeat.output.consoleEnabled":"true","metadata.storageClass":\"${storageclass}\","imagePullSecrets":"ownerServiceInstanceUsername":""},"transientFields":{}}
它给我这个错误:
{"code":400,"message":"parsing body body from \"\" failed, because invalid character 's' looking for beginning of value"}* Could not resolve host: serviceInstanceDisplayName; Unknown error
12:24:32 * Closing connection 1
12:24:32 curl: (6) Could not resolve host: serviceInstanceDisplayName; Unknown error
12:24:33 * Could not resolve host: serviceInstanceNamespace; Unknown error
我觉得你好像少了一个括号,试着在最后加上}
。
关于 json 格式的参数仅使用 "$storageclass"
。或类似这样的内容:
json="{\"name\": \"$name\", \"text\": \"$Text\"}"
要在 POST 命令中替换 JSON 中的变量,您需要这样做:
"'"${variableName}"'"
单引号内的双引号位于双引号内。 所以它看起来像这样:
curl -X POST www.example.com -d '{"country": "city","province":"'"${variableName}"'"}'