Pergunta

I was wondering if there was a way to do this in Hudson (or with any of the various plugins). My IDEAL scenario:

I want to trigger a build based on a job through a REST-like API, and on that build, I want it to return me a job ID. After-wards, I would like to poll this ID to see its status. When it is done, I would like to see the status, and the build number.

Now, since I can't seem to get that working, here is my current solution that I have yet to implement:

When you do a REST call to do a build, its not very REST-ful. It simply returns HTML, and I would have to do a kind of parsing to get the job ID. Alternatively, I can do a REST call for all the history listing all the jobs, and the latest one would be the one I just built. Once I have that, I can poll the console output for the output of the build.

Anyone know a way I can implement my "ideal" solution?

Foi útil?

Solução

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.

Outras dicas

And what if you don't want the latest build number, but you want the build number of the build that was triggered by hitting the build URL ?

As far as I can tell, hitting that URL returns a 302 that redirects you to the job's mainpage, with no indication whatsoever of what the build number is of the one that you triggered.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top