Hudson 触发器远程构建会出现禁止的 403 错误

发布于 2024-08-27 23:56:19 字数 346 浏览 4 评论 0原文

我在部署 hudson 的同一台机器上有一个 shell 脚本,执行该脚本时,它会在 hudson 构建触发器 URL 上调用 wget。由于它是同一台机器,我将其访问为 http://localhost:8080/hudson /job/jobname/build?token=sometoken

通常,这应该会触发项目的构建。但当我这样做时,我得到了 403 禁止。有人知道为什么吗?我已经使用浏览器尝试过此操作,它触发了构建,但通过命令行它似乎不起作用。有什么想法吗?

I have a shell script on the same machine that hudson is deployed on and upon executing it, it calls wget on a hudson build trigger URL. Since its the same machine, I access it as http://localhost:8080/hudson/job/jobname/build?token=sometoken

Typically, this is supposed to trigger a build on the project. But I get a 403 forbidden when I do this. Anybody has any idea why? I have tried this using a browser and it triggers the build, but via the command line it doesn't seem to work. Any ideas?

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

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

发布评论

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

评论(3

明月松间行 2024-09-03 23:56:19

我想通了。显然,如果 Hudson 使用安全机制进行保护,您需要对构建请求进行身份验证。有关更多详细信息,请参阅此 wiki 链接 http://wiki.hudson-ci。 org/display/HUDSON/Authenticating+scripted+clients

由于我使用了 Hudson 附带的身份验证机制,因此调用了涉及的构建脚本。我曾经

wget --auth-no-challenge --http-user=user --http-password=password http://hudson.yourcompany.com/job/your_job/build?token=TOKEN

运行构建脚本。

I figured it out. Apparently if Hudson is protected using a security mechanism, you need to authenticate the build requests. See this wiki link for more details http://wiki.hudson-ci.org/display/HUDSON/Authenticating+scripted+clients

Since I used the auth mechanism that was shipped with Hudson, calling the build scripts invovled. I used

wget --auth-no-challenge --http-user=user --http-password=password http://hudson.yourcompany.com/job/your_job/build?token=TOKEN

to run the build script.

放赐 2024-09-03 23:56:19

如果您使用基于矩阵的安全性,则可以将作业读取和作业构建权限设置为匿名,这样您就不需要在提交后挂钩中使用用户和密码。

另一个提示是打开轮询而不设置日期并使用以下 URL:

http://hudson.yourcompany .com/job/your_job/polling?token=TOKEN

如果 svn 发生更改,您的作业就会构建(更改其他项目、创建标签等时无需构建)

If you use matrix-based security, you can set Job Read and Job Build permission to Anonymous, so you don't need a user and password in your post-commit hook.

Another tip is to turn on polling without setting a date and use this URL:

http://hudson.yourcompany.com/job/your_job/polling?token=TOKEN

Your job will be build just if there were svn changes (no need to build when changing other projects, creating tags etc.)

兮颜 2024-09-03 23:56:19

我遇到了同样的错误。就我而言,我必须将 Jenkins-Crumb 标头添加到 HttpPost 对象才能使其正常工作。

post.addHeader("Jenkins-Crumb","crumb value");

要查找 Jenkins 实例的 crumb 值,请在浏览器中安装 Firebug 或任何插件,这将帮助您查看请求标头。转到您的职位页面 http://server_name:port/jenkins/job/job_name
按 F12 激活 Firebug,进入 Net 选项卡。单击页面右上角的启用自动刷新链接。现在,每 5 秒您应该会看到一个 Ajax 请求来获取 buildHistory。在该请求中,检查标头。应该有 Jenkins-Crumb 的标头,它也可以位于名称 .crumb 下,具体取决于您使用的 Jenkins 版本。你可以在 Java 代码中使用它。

I got the same errors. In my case I had to add the Jenkins-Crumb header to the HttpPost object to make it work.

post.addHeader("Jenkins-Crumb","crumb value");

To find the crumb value for your Jenkins instance, install Firebug or any plugin n your browser which will help you see the request headers. Go to your job page at http://server_name:port/jenkins/job/job_name
Press F12 to activate Firebug, got to Net tab. Click Enable Auto - refresh link at top right of your page. Now every 5 seconds you should see an Ajax Request being made to fetch the buildHistory. In that request, examine the headers. There should be a header for Jenkins-Crumb, it can also be under name .crumb depending the Jenkins version you are using. You it in your Java code.

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