触发参数化构建与卷曲和碎屑 [英] Trigger parameterized build with curl and crumb
问题描述
我在SO上看到过类似的帖子,但不是我想要做的(或至少没有一个命令运行的完整示例)。
我试图远程触发使用curl的Jenkins上的参数化构建。我已经启用防止跨站点请求伪造,因此我还需要传递一个有效的碎屑。
我的脚本如下:
#!/ bin / bash
json ={\parameter\:[{\P1\ :\param1\,\P2\:\param2\,\P3\:\param3\}]}
crumb =`curlhttp:// 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
我也尝试修改我传递的网址卷曲到:
USERNAME:APITOKEN @ SERVER
和
USERNAME:PASSWORD @ SERVER
/ p>
*关于连接()到SERVER端口8080(#0)
*尝试SERVER ...连接
*连接到SERVER(SERVER)端口8080(#0)
*使用基本用户'USERNAME'的服务器认证
> POST / job / JOB_NAME / buildWithParameters HTTP / 1.1
>授权:基本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
>主机:SERVER:8080
>接受:* / *
> .crumb:776eb589e8b930d9f06cfc2df885314c
> Content-Length:168
> Content-Type:application / x-www-form-urlencoded
>
< HTTP / 1.1 403请求中不包括有效的碎片
< Content-Type:text / html; charset = ISO-8859-1
< Cache-Control:must-revalidate,no-cache,no-store
< Content-Length:1469
<服务器:Jetty(8.y.z-SNAPSHOT)
<
所以看起来我没有正确传递碎片,但我不知道正确的格式是
。
curl -H.crumb:xxxxxxxxxxxxxxxxxxxxxx
I've seen similar posts to this on SO, but not quite exactly what I am trying to do (or at least no full examples of a command to run).
I am trying to remotely trigger a parameterized build on Jenkins using curl. I have 'Prevent Cross Site Request Forgery' enabled so I also need to pass a valid crumb.
The script I have is below:
#!/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"
I've also tried modifying the URL I'm passing to curl to either:
USERNAME:APITOKEN@SERVER
and
USERNAME:PASSWORD@SERVER
Output from curl is:
* 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)
<
So it looks like I'm not passing the crumb properly, but I'm not sure what the correct format of the command should be.
The correct format is:
curl -H ".crumb:xxxxxxxxxxxxxxxxxxxxxx"
这篇关于触发参数化构建与卷曲和碎屑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!