Group jobs together in Jenkins or Serialize them or run them in Sequence

Go To StackoverFlow.com

2

I have three jobs that I would like to serialize in Jenkins.

They should run as a block after a job that triggers them:

Job1 -> [A,B,C]
Job2 -> [A,B,C]

Right now when Job1 is triggered twice, I get the following behavior:

Order that jobs are run now:
-Job1
-Job2
-A
-B
-(job A or C)
-Order is not guaranteed after this

What I would like to see is:

Order that jobs are run:
-Job1
-Job2
-A (from Job1)
-B (from Job1)
-C (from Job1)
 ------------
-A (from Job2)
-B (from Job2)
-C (from Job2)
2012-04-03 21:28
by Anas Alkhatib


2

So, this is the solution I found:

Using the Jenkins Parameterized Trigger plug-in, an extra Build step is available:

Trigger/call builds on other projects

On Job1 add three build triggers:

Projects to Build: JobA

[x] Block until the triggered projects finish their builds

Projects to Build: JobB

[x] Block until the triggered projects finish their builds

Projects to Build: JobC

[x] Block until the triggered projects finish their builds

Do the same on Job2.

Add a lock that is shared between the two Jobs 1 and 2.

This way when Job 1 and Job 2 are triggered they will wait for each other. And each Job won't be marked as passed until all the Jobs A->B>C run and are successful.

More options are available to control the return value of each build step , whether it should depend on the result of the triggered job or continue regardless of the result.

Fail this build step if the triggered build is worse or equal to    

Mark this build as failure if the triggered build is worse or equal to  

Mark this build as unstable if the triggered build is worse or equal to 
2012-04-06 14:46
by Anas Alkhatib


2

Have a look at the Jenkins Locks and Latches plugin.

2012-04-03 21:37
by gareth_bowles
From what I have seen from using it, a lock only guarantees that none of the jobs will run concurrently. But no way to make sure they run in serial. Unless I am messing something about the usage of locks.

If there was a way to create a job that calls Job A,B,C in order and doesn't succeed until all are finished, then that job could acquire the lock - Anas Alkhatib 2012-04-04 03:15



1

I cannot think of a way to do exactly what you want in Jenkins. Maybe Jenkins is not the tool for you?

Another way to approach this would be: Your question actually presents a solution to your problem (a bunch of jobs and their execution order) and you are asking how to implement it.

Would you be willing to explain what is your goal, what is it you want to achieve? Maybe some Jenkins expert can then tell you how you can do it using Jenkins.

2012-04-04 20:19
by sti
Job1 is a trigger in gerrit, on each code review I want to: (A) Setup a machine -> (B) Run all the Tests once

On the nightly run: to: (A) Setup a machine -> (B) Run all the Tests once -> (C) Run all the Tests several timesAnas Alkhatib 2012-04-04 21:10

Ads