使用 curl 和 crumb 触发参数化构建 [英] Trigger parameterized build with curl and crumb

查看:24
本文介绍了使用 curl 和 crumb 触发参数化构建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 SO 上看到过类似的帖子,但并不完全是我想要做的(或者至少没有运行命令的完整示例).

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).

我正在尝试使用 curl 在 Jenkins 上远程触发参数化构建.我启用了防止跨站点请求伪造",因此我还需要传递有效的面包屑.

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.

我的脚本如下:

#!/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:

I've also tried modifying the URL I'm passing to curl to either:

USERNAME:APITOKEN@SERVER

USERNAME:PASSWORD@SERVER

curl 的输出是:

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.

推荐答案

正确格式如下:

curl -H ".crumb:xxxxxxxxxxxxxxxxxxxxxx"

这篇关于使用 curl 和 crumb 触发参数化构建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆