Jenkins / Hudson: How to Build periodically only after another project are built

StackOverflow https://stackoverflow.com/questions/22562453

  •  18-06-2023
  •  | 
  •  

Question

I have a project (p1) that is built nightly. Every Tuesday, I want to have a second project (p2) built, but only on successful completion of p1. p2 relies on successful build of p1 so p2 must not be triggered to run if that days' p1 fails.

The only way I can think of doing this is to create two identical p1 jobs p1a and p1b:

  • p1a runs every day except tuesday
  • p1b runs on tuesday, when finished successfully, triggers p2

This is a bit a mess however, as it creates multiple versions of p1 to maintain, with their own build history, etc...

Anyone know a better way to accomplish this?

Était-ce utile?

La solution

You can use an Exclusion plugin.

  • Setup the same "resource" string for both jobs (read the plugin page for details)
  • The p1 job should be on a nightly schedule to start earlier than p2 job
  • The p1 job should be on a Tuesday-only schedule to start slightly later than p1

This way, on Tuesdays, when p2 runs, the "resource" will already be in-use by p1. I haven't actually used this plugin, so not sure if it will cause p2 to wait or fail, but if the later is true, you can configure p2 to retry failed builds with something like this plugin

Alternatively, the Conditional Build Step plugin can be used.

  • In p1 configure a Conditional Build Step after the building step (so if the building step fails, it never executes.
  • It uses Run Condition plugin, which will allow to select Day of Week as a condition. Select Tuesday
  • Then use Parameterized Trigger Plugin to add Trigger/call builds on other projects build step that will trigger p2

Autres conseils

There's a stack overflow question on Conditional Post build steps which might be of interest. In particular the post about the conditional post build plugin

Perhaps using that plugin and getting the current day of the week using a custom script and verify it's tuesday would solve your problem

You could set the starting time of both projects to the same (p2 a minute later or so).

Then you could define a lock (throttle concurrent build plugin or locks and latches) to allow only one of your jobs to run concurrently.

Alternatively, you could indeed create two jobs using the jobDSL plugin or something similar.

I found a fairly recent plugin, BuildResultTrigger Plugin. It allows conditional builds on multiple success of other jobs. It also allows for scheduling, so it can be set to poll the other jobs for successful condition: https://wiki.jenkins-ci.org/display/JENKINS/BuildResultTrigger+Plugin

The one draw back is it's can't be 'triggered' by another job, but only by scheduled polling.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top