Anas Alkhatib
Anas Alkhatib

Reputation: 1150

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

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)

Upvotes: 2

Views: 5218

Answers (3)

Anas Alkhatib
Anas Alkhatib

Reputation: 1150

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 

Upvotes: 2

sti
sti

Reputation: 11075

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.

Upvotes: 1

gareth_bowles
gareth_bowles

Reputation: 21130

Have a look at the Jenkins Locks and Latches plugin.

Upvotes: 2

Related Questions