Lewis
Lewis

Reputation: 93

Jenkins: Trigger related builds in a specific order when any of them are triggered by SCM

Say I have three jobs, A, B and C. They all run integration tests that interact with each other. C is dependent on B, B is dependent on A.

Is there a way to trigger A, then B, then C in that order when an SCM poll triggers any of the three projects?

E.g. I check code into A, and a few minutes later I check code into C. I need A to be built first, then build B to run integration tests, then build C. But I can't guarantee this with conventional polling intervals.

I've looked at the parametrized build plugin but I can't figure out a way to do it without an infinite loop of builds.

Edit: The answer below seems to be the best option BUT I'm using Mercurial and can't find a way to check out multiple Mercurial repos.

Upvotes: 1

Views: 2032

Answers (2)

Anguirel
Anguirel

Reputation: 36

Granted this is a stale question, but I have an alternative you can use if you're still dealing with this (or someone else runs across this like I did in a search for a similar issue):

  • Job A1 - polls repo A but does not sync, triggers Job A2
  • Job B1 - polls repo B but does not sync, triggers Job A2
  • Job C1 - polls repo C but does not sync, triggers Job A2
  • Job A2 - current Job A, triggers Job B2
  • Job B2 - current Job B, triggers Job C2
  • Job C2 - current Job C

The "does not sync" probably isn't necessary (it'll just sync again on the related job), but would preserve the exact functionality of your current chain.

Upvotes: 2

Slav
Slav

Reputation: 27515

One way is to configure Job A to always trigger Job B, and Job B to always trigger job C. This will ensure that they run in the order that you need.

Now, you want SCM changes to either of the 3 jobs to start the chain. In Job A, you can do SCM checkouts for all 3 repository location (just don't utilize them in Job A).

This way, the polling will apply to all 3 location, will trigger Job A which in turn triggers the proper chain that you want

Upvotes: 1

Related Questions