我在SO上看过类似的帖子,但并不完全是我想要做的(或者至少没有完整的命令来运行).
我试图使用curl远程触发Jenkins上的参数化构建.我启用了"防止跨站点请求伪造",因此我还需要传递有效的碎屑.
我的脚本如下:
#!/bin/bash json="{\"parameter\": [{ \"P1\": \"param1\", \"P2\": \"param2\", \"P3\": \"param3\" }]}" crumb=`curl "http://SERVER/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,%22:%22,//crumb)"` curl -v -H $crumb -X POST http://SERVER/job/JOB_NAME/buildWithParameters -d token=runme --data-urlencode json="$json"
我也尝试修改我传递给以下任何一个的URL:
USERNAME:APITOKEN@SERVER
和
USERNAME:PASSWORD@SERVER
卷曲的输出是:
* About to connect() to SERVER port 8080 (#0) * Trying SERVER... connected * Connected to SERVER (SERVER) port 8080 (#0) * Server auth using Basic with user 'USERNAME' > POST /job/JOB_NAME/buildWithParameters HTTP/1.1 > Authorization: Basic bjAwNjY5MjI6YWxLaW5kaTg= > User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.13.1.0 zlib/1.2.3 libidn/1.18 libssh2/1.2.2 > Host: SERVER:8080 > Accept: */* > .crumb:776eb589e8b930d9f06cfc2df885314c > Content-Length: 168 > Content-Type: application/x-www-form-urlencoded > < HTTP/1.1 403 No valid crumb was included in the request < Content-Type: text/html;charset=ISO-8859-1 < Cache-Control: must-revalidate,no-cache,no-store < Content-Length: 1469 < Server: Jetty(8.y.z-SNAPSHOT) <
所以看起来我没有正确地传递碎屑,但我不确定该命令的正确格式应该是什么.