If you have the executors, the builds should run in parallel. Given the
following script in the Script Console (and jobs named wait1..wait4 with
different durations):
---
def futures = []
[1, 2, 3, 4].each {
futures.add Jenkins.instance.getItemByFullName("wait${it}").scheduleBuild2(0)
}
futures.each {
println it.get().time
println it.get().duration // millis
}
---
The following output is printed:
---
Sun Mar 09 23:18:12 CET 2014
20025
Sun Mar 09 23:18:12 CET 2014
10031
Sun Mar 09 23:18:22 CET 2014
25027
Sun Mar 09 23:18:32 CET 2014
15026
---
I have two executors, and you can see the first two started at the same time,
the third when the second was finished, the fourth when the first was finished.
Note that get() is a blocking call, and it waits for the related build to
complete. That build isn't necessarily the one finishing first -- there's a
chance you'll wait for the longest-running build first in the second loop, only
to then get the subsequent results immediately, because they've finished long
ago. Perhaps you can use Future.get(long,TimeUnit) instead if you want to
present the results in the order they are available.
Another possible issue: Did you make sure that your queue does not simply
collapse multiple executions of the same job into one, because they're
considered equal?
On 09.03.2014, at 22:52, dev123 <[email protected]> wrote:
> Not sure I understand I now do:
>
>
> for (int i = 0; i < 4; i++) {
> try {
> QueueTaskFuture<?> scheduleBuild2 = project.scheduleBuild2(0, new
> Cause.UserCause(), myActions[i]);
> queue.add(scheduleBuild2);
> } catch (Exception e) {
> throw new AbortException(e.getMessage());
> }
> }
>
> for (QueueTaskFuture<?> q : queue) {
> q.get();
> }
>
>
> I need to get the results from each job and print some info but it still does
> not execute in parallel.
>
> I also found this:
>
> Queue$Item item = Jenkins.getInstance().getQueue().schedule2(null, 0,
> myActions[i])
>
> But I still does not give me what I want.
>
>
> On Sunday, March 9, 2014 10:32:31 PM UTC+1, Daniel Beck wrote:
> Don't immediately call .get(), instead assign the Future returned from
> scheduleBuild2 to a variable. Only .get() once you're willing to wait for the
> build to complete.
>
> On 09.03.2014, at 22:27, dev123 <[email protected]> wrote:
>
> > In a jenkins plugin I am writing I need to run 5 jobs in parallel.
> > Currently I do (sequentially):
> >
> > for (int i = 0; i < 4; i++) {
> > try {
> > build = project.scheduleBuild2(0, new Cause.UserCause(),
> > myActions[i]).get();
> > } catch (Exception e) {
> > throw new AbortException(e.getMessage());
> > }
> > }
> >
> > How do I trigger these jobs to run in parallel - each one on a separate
> > executor?
> >
> >
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Jenkins Users" group.
> > To unsubscribe from this group and stop receiving emails from it, send an
> > email to [email protected].
> > For more options, visit https://groups.google.com/d/optout.
>
--
You received this message because you are subscribed to the Google Groups
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.