【发布时间】:2014-01-18 04:22:43
【问题描述】:
我有一个 curl 语句,我在 Jenkins Execute Shell Script 插件的 shell 脚本中运行,它将返回一个 json 对象:{"request_id":"52d4520c09228dc810000096"}。
Curl 语句运行良好并返回正确的响应 json 对象。
我需要解析这个对象并取回该值以用作下一个 Jenkins 作业的参数。目前使用 tr 和 cut 来解析 json 响应。
当我尝试这段代码时它失败了:
curl -s -X POST -H "Accept:application/json" -d "{my parameters}" http://my_http_post_url | tr -d '{}"' | cut -f 2 -d ':' - > ${response_id};
失败:
cannot create : Directory nonexistent
+ cut -f 2 -d : -
+ curl -s -X POST -H Accept:application/json -d {my params} http://my_http_post_url
tr: write error: Broken pipe
Build step 'Execute shell' marked build as failure
也试过这个:
${response_id}=$(curl -s -X POST -H "Accept:application/json" -d "{my parameters}" http://my_http_post_url | tr -d '{}"' | cut -f 2 -d ':');
失败(注意:52d4520c09228dc810000096 是正确的响应 ID):
+ cut -f 2 -d :
+ curl -s -X POST -H Accept:application/json -d {my params} http://my_http_post_url
+ tr -d {}"
+ = 52d4520c09228dc810000096
/tmp/hudson3217430586060280102.sh: 2: /tmp/hudson3217430586060280102.sh: = 52d4520c09228dc810000096: not found
Build step 'Execute shell' marked build as failure
【问题讨论】: