我見過類似的帖子到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:[email protected]
和
USERNAME:[email protected]
捲曲輸出爲:
* 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)
<
所以看起來我沒有正確傳遞碎屑,但我不確定該命令的正確格式應該是什麼。
[Jenkins REST API Create job]可能重複(https://stackoverflow.com/questions/38137760/jenkins-rest-api-create-job) – kenorb