我在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"
我还尝试将要传递给curl的URL修改为:
USERNAME:APITOKEN@SERVER
和
USERNAME:PASSWORD@SERVER
curl的输出是:
* 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) <
因此,看来我没有正确传递面包屑,但是我不确定命令的正确格式是什么。
正确的格式如下:
curl -H ".crumb:xxxxxxxxxxxxxxxxxxxxxx"