Starting job with Hudson over HTTP API - job number is hard to know

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Starting job with Hudson over HTTP API - job number is hard to know

Evgeny Goldin
Hello all,

We're starting a Hudson job from Groovy script, sending an HTTP request:
$jobUrl/buildWithParameters?a=b&c=d

The response contains a big HTML so in order to know the job number - we search with regex for the first appearance of #N. It's not really nice and reliable (when other jobs are invoked at the same time) so is it possible somehow to get an exact job number in return?

Thank you!
Best regards,
Evgeny
http://evgeny-goldin.com/
Reply | Threaded
Open this post in threaded view
|

Re: Starting job with Hudson over HTTP API - job number is hard to know

Michael Donohue
The HTTP request is to enqueue the job to be built.  In the case that there is nothing in the queue, it will start immediately, but otherwise it will be delayed until the queue assigns it to an executor.  Because a build number is not assigned until the job starts, it is not possible for this API to reliably produce a build number.   

There are ways of guessing, but that won't be entirely reliable, for example if a job with different parameters is ahead in the queue, but gets cancelled, that will alter the build number ultimately assigned to the job you just started.

-Michael
(646) 833-8884


On Sat, Feb 13, 2010 at 10:16 AM, Evgeny Goldin <[hidden email]> wrote:

Hello all,

We're starting a Hudson job from Groovy script, sending an HTTP request:
$jobUrl/buildWithParameters?a=b&c=d

The response contains a big HTML so in order to know the job number - we
search with regex for the first appearance of #N. It's not really nice and
reliable (when other jobs are invoked at the same time) so is it possible
somehow to get an exact job number in return?

Thank you!

-----
Best regards,
Evgeny
http://evgeny-goldin.com/

--
View this message in context: http://n4.nabble.com/Starting-job-with-Hudson-over-HTTP-API-job-number-is-hard-to-know-tp1554490p1554490.html
Sent from the Hudson users mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: Starting job with Hudson over HTTP API - job number is hard to know

Evgeny Goldin
Ok, when it starts immediately - may be then the job number can be returned?

Today, I have hard time triggering the job and polling it's console log for results - I need to guess it's number :(
Best regards,
Evgeny
http://evgeny-goldin.com/
Reply | Threaded
Open this post in threaded view
|

Re: Starting job with Hudson over HTTP API - job number is hard to know

Michael Donohue
Without knowing your overall goal, it's hard to say whether this is the right approach, but trying to get an external script to correlate the request to build a job against what job actually starts as a result seems rather brittle.   Perhaps you could write a Hudson plugin that does more precisely what you want with the console output, exposing the desired data via some permalinks, or something similar. 

-Michael
(646) 833-8884


On Sun, Feb 14, 2010 at 7:31 PM, Evgeny Goldin <[hidden email]> wrote:

Ok, when it starts immediately - may be then the job number can be returned?

Today, I have hard time triggering the job and polling it's console log for
results - I need to guess it's number :(

-----
Best regards,
Evgeny
http://evgeny-goldin.com/

--
View this message in context: http://n4.nabble.com/Starting-job-with-Hudson-over-HTTP-API-job-number-is-hard-to-know-tp1554490p1555581.html
Sent from the Hudson users mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: Starting job with Hudson over HTTP API - job number is hard to know

Kirill Evstigneev @spera
In reply to this post by Evgeny Goldin
You could:
0) Add a "cookie" parameter to your job.
1) Guess the next build number by incrementing the last build number:
    build_number = ${job_url}/lastBuild/buildNumber + 1
2) Queue a build.
3) Wait until the build record is created
    ${job_url}/lastBuild/buildNumber == ${build_number}
4) Pool for the build to start
    ${job_url}/${build_number}/api/xml?xpath=/*/building/text()
    (should be "true" for running job)
5) Compare the build parameter with the passed value
    ${job_url}/${build_number}/api/xml?xpath=/*/action/parameter[name=${cookie_parameter_name}]/value/text() == ${cookie_parameter_value}

But even such a double-check sequence is quite unreliable. Hudson itself has no relation between a build request and a build.
Reply | Threaded
Open this post in threaded view
|

Re: Starting job with Hudson over HTTP API - job number is hard to know

Kohsuke Kawaguchi
Administrator
In reply to this post by Michael Donohue
A relatively easy approach is to use the Hudson CLI. It includes the
scheduling method both in the async form that just submits the job, as
well as in the sync mode, which waits for the completion of the job.

2010/2/14 Michael Donohue <[hidden email]>:

> Without knowing your overall goal, it's hard to say whether this is the
> right approach, but trying to get an external script to correlate the
> request to build a job against what job actually starts as a result seems
> rather brittle.   Perhaps you could write a Hudson plugin that does more
> precisely what you want with the console output, exposing the desired data
> via some permalinks, or something similar.
>
> -Michael
> (646) 833-8884
>
>
> On Sun, Feb 14, 2010 at 7:31 PM, Evgeny Goldin <[hidden email]> wrote:
>>
>> Ok, when it starts immediately - may be then the job number can be
>> returned?
>>
>> Today, I have hard time triggering the job and polling it's console log
>> for
>> results - I need to guess it's number :(
>>
>> -----
>> Best regards,
>> Evgeny
>> http://evgeny-goldin.com/
>>
>> --
>> View this message in context:
>> http://n4.nabble.com/Starting-job-with-Hudson-over-HTTP-API-job-number-is-hard-to-know-tp1554490p1555581.html
>> Sent from the Hudson users mailing list archive at Nabble.com.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [hidden email]
>> For additional commands, e-mail: [hidden email]
>>
>
>



--
Kohsuke Kawaguchi

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]