Jenkins JSON 结果构建请求

发布于 2024-11-28 06:42:14 字数 351 浏览 1 评论 0原文

我正在寻找一种通过调用返回 JSON 的 url 来请求构建请求的方法,以便我能够使用 git 设置一个钩子,以便在每次推送到远程存储库后验证单元测试。我发现网址看起来像我想要的,所以我尝试了:

http://www.doamin.com:8082/job/bare-bone-test/build/api/json

但是当我尝试在浏览器中执行此操作时,我得到了

Firefox 检测到服务器正在重定向请求 这个地址以一种永远不会完成的方式

即使它确实触发了该作业的构建, 。这是请求将返回 JSON 响应的构建的正确方法吗?

I was looking for a way to request a build request through calling a url that would return JSON so that I would be able to setup a hook with git to validate unit tests after each push to the remote repository. I found url that looked like what I want so I tried:

http://www.doamin.com:8082/job/bare-bone-test/build/api/json

however when I try to do there in my browser I get the

Firefox has detected that the server is redirecting the request for
this address in a way that will never complete

even though it does trigger a build of that job. Is this the correct way to request a build that will return a JSON response?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风渺 2024-12-05 06:42:14

根据文档

提交作业

对于没有参数的作业,您只需执行
HTTP GET 上

JENKINS_URL/job/JOBNAME/build?token=TOKEN

TOKEN 在作业配置中设置。

如果有参数,则需要发送JSON。这是一个片段
shell,带有一些额外的换行符以提高可读性。

json="{\"参数\": [{\"名称\": \"任务文件\", \"值\":
\"$taskfile\"}, {\"name\": \"task\", \"value\": \"$task\"}, {\"name\":
\“jobParameters \”,\“值\”:\“$ jobargs \”}],\“\”:\“\”}”
url=http://hudson.basistech.net/job/benson-segmentation-training/build
curl -X POST $url -d token=zorn --data-urlencode json="$json"

我不太确定 TOKEN 字段是否真的有必要。我能够使用简单的 get to the job//build URL 来启动构建:

curl -v http://localhost:8080/job/testjob/build
* About to connect() to localhost port 8080 (#0)
*   Trying 127.0.0.1... connected
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET /job/testjob/build HTTP/1.1
> User-Agent: curl/7.21.3 (x86_64-pc-linux-gnu) libcurl/7.21.3 OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18
> Host: localhost:8080
> Accept: */*
> 
< HTTP/1.1 302 Found
< Server: Winstone Servlet Engine v0.9.10
< Location: http://localhost:8080/job/testjob/
< Content-Length: 0
< Connection: Keep-Alive
< Date: Mon, 08 Aug 2011 20:48:37 GMT
< X-Powered-By: Servlet/2.5 (Winstone/0.9.10)
< 
* Connection #0 to host localhost left intact
* Closing connection #0

对于 git post-commit 挂钩,这应该足够了。

重定向,什么鬼?

您看到无限重定向问题的原因是 build/api/json URL 重定向到 build/api 端点(我认为 build/api/json 的处理程序>build url 尝试通过截掉 URL 的最后一部分来重定向回作业状态页面)。由于某些奇怪的原因,build/api 重定向回自身。我认为构建不支持 api/json 后缀,但如上所示,不需要它。

According to the documentation:

Submitting jobs

For a job with no parameters, you need merely go an
HTTP GET on

JENKINS_URL/job/JOBNAME/build?token=TOKEN

where TOKEN is set up in the job configuration.

If you have parameters, you need to send JSON. Here's a snipped of
shell, with a few extra newlines to be more readable.

json="{\"parameter\": [{\"name\": \"taskfile\", \"value\":
\"$taskfile\"}, {\"name\": \"task\", \"value\": \"$task\"}, {\"name\":
\"jobParameters\", \"value\": \"$jobargs\"}], \"\": \"\"}"
url=http://hudson.basistech.net/job/benson-segmentation-training/build
curl -X POST $url -d token=zorn --data-urlencode json="$json"

I'm not quite sure if the TOKEN field is really necessary. I was able to kick off a build using a simple get to the job//build URL:

curl -v http://localhost:8080/job/testjob/build
* About to connect() to localhost port 8080 (#0)
*   Trying 127.0.0.1... connected
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET /job/testjob/build HTTP/1.1
> User-Agent: curl/7.21.3 (x86_64-pc-linux-gnu) libcurl/7.21.3 OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18
> Host: localhost:8080
> Accept: */*
> 
< HTTP/1.1 302 Found
< Server: Winstone Servlet Engine v0.9.10
< Location: http://localhost:8080/job/testjob/
< Content-Length: 0
< Connection: Keep-Alive
< Date: Mon, 08 Aug 2011 20:48:37 GMT
< X-Powered-By: Servlet/2.5 (Winstone/0.9.10)
< 
* Connection #0 to host localhost left intact
* Closing connection #0

For a git post-commit hook, this should be enough.

Redirect, wtf?

The reason you're seeing the infinite redirect issue, is that the build/api/json URL redirects to the build/api endpoint (I think the handler for the build url tries to redirect back to the job status page by chopping off the last part of the URL). For some strange reason, build/api redirects back to itself. I don't think that the build supports the api/json suffix, but as shown above, it isn't needed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文