如何在Jenkins Slave中的POST请求中正确使用变量

这是我的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
ufo748 回答:如何在Jenkins Slave中的POST请求中正确使用变量

我认为您好像错过了一个括号,请尝试最后添加}

关于json格式的参数,仅使用"$storageclass"。或类似的东西:

json="{\"name\": \"$name\",\"text\": \"$Text\"}"
,

要在POST命令中替换JSON中的变量,您需要执行以下操作:

"'"${variableName}"'"

在双引号内的单引号内的双引号。 所以看起来像这样:

 curl -X POST www.example.com -d '{"country": "city","province":"'"${variableName}"'"}'
本文链接:https://www.f2er.com/3093087.html

大家都在问