1

我想知道在 Hudson 中是否有办法做到这一点(或使用任何各种插件)。我的理想场景:

我想通过类似 REST 的 API 触发基于作业的构建,并且在该构建上,我希望它返回一个作业 ID。之后,我想轮询此 ID 以查看其状态。完成后,我想查看状态和内部版本号。

现在,由于我似乎无法让它工作,这是我目前尚未实施的解决方案:

当您进行 REST 调用以进行构建时,它不是非常 REST-ful。它只是返回 HTML,我必须进行某种解析才能获得作业 ID。或者,我可以对列出所有作业的所有历史记录进行 REST 调用,最新的将是我刚刚构建的那个。一旦我有了它,我就可以轮询控制台输出以获取构建的输出。

任何人都知道我可以实现我的“理想”解决方案的方法吗?

4

2 回答 2

5

Yes, you can use the Hudson Remote API for this (as @Dan mentioned). Specifically, you need to configure your job to accept Remote Triggers (Job Configuration -> Build Triggers -> Trigger builds remotely) and then you can fire off a build with a simple HTTP GET to the right url.

(You may need to jump through a couple additional hoops if your Hudson requires authentication.)

I'm able to start a Hudson job with wget:

wget --auth-no-challenge --http-user=test --http-password=test "http://localhost:8080/job/My job/build?TOKEN=test"

This returns a bunch of HTML with a build number #20 that you could parse. The build number can then be used to query whether the job is done / successful.

You can examine the Hudson Remote API right from your browser for most of the Hudson web pages that you normally access by appending /api (or /api/xml to see the actual XML output), e.g. http://your-hudson/job/My job/api/.


Update: I see from your question that you probably know much of what I wrote. It is worth exploring the built-in Hudson API documentation a bit. I just discovered this tidbit that might help.

You can get the build number of the latest build (as plain text) from the URL: http://your-hudson/job/My job/lastBuild/buildNumber

Once you have the build number, I think the polling and job status is straightforward once you understand the API.

于 2010-11-11T00:11:10.490 回答
2

如果您不想要最新的内部版本号,但您想要通过点击构建 URL 触发的构建版本号怎么办?

据我所知,点击该 URL 会返回一个 302,将您重定向到作业的主页,但没有任何迹象表明您触发的版本号是什么。

于 2011-05-30T11:57:00.000 回答