How to conditionally build other projects?
Solution 1:
If I understood it correct you should be able to do this by following these Steps:
- First Build Step:
- Does the regular work. In your case: building, unit testing and packaging of the web application
- Depending on the result let it create a file with a specific name.
- This means if you want the low-risk-change to run afterwards create a file low-risk.prop
- Second Build Step:
- Create a Trigger/call builds on other projects Step from the Parameterized-Trigger plugin.
- Entery the name of your low-risk job into the Projects to build field
- Click on: Add Parameter
- Choose: Parameters from properties File
- Enter low-risk.prop into the Use properties from file Field
- Enable Don't trigger if any files are missing
- Third Build Step:
- Check if a low-risk.prop file exists
- Delete the File
Do the same for the high-risk job
Now you should have the following Setup:
- if a file called low-risk.prop occurs during the first Build Step the low-risk job will be started
- if a file called high-risk.prop occurs during the first Build Step the high-risk job will be started
- if there's no .prop File nothing happens
And that's what you wanted to achieve. Isn't it?
Solution 2:
Have you looked at the Conditional Build Plugin? (https://wiki.jenkins.io/display/JENKINS/Conditional+BuildStep+Plugin)
I think it can do what you're looking for.
Solution 3:
If you want a conditional post-build step, there is a plugin for that:
https://wiki.jenkins-ci.org/display/JENKINS/Post+build+task
It will search the console log for a RegEx you specify, and if found, will execute a custom script. You can configure fairly complex criteria, and you can configure multiple sets of criteria each executing different post build tasks.
It doesn't provide you with the usual "build step" actions, so you've got to write your own script there. You can trigger execution of the same job with different parameters, or another job with some parameters, in standard ways that jenkins supports (for example using curl)
Yet another alternative is Jenkins text finder plugin:
https://wiki.jenkins-ci.org/display/JENKINS/Text-finder+Plugin
This is a post-build step that allows to forcefully mark a build as "unstable" if a RegEx is found in console text (or even some file in workspace). So, in your build steps, depending on your conditions, echo a unique line into console log, and then do a RegEx for that line. You can then use "Trigger parameterized buids" and set the condition as "unstable". This has an added benefit of visually marking the build different (with a yellow ball), however you only have 1 conditional option with this method, and from your OP, looks like you need 2.
Try a combination of these 2 methods:
Solution 4:
Do you use Ant for your builds?
If so, it's possible to do conditional building in ant by having a set of environment variables your build scripts can use to conditionally build. In Jenkins, your build will then be building all of the projects, but your actual build will decide whether it builds or just short-circuits.
Solution 5:
I think the way to do it is to add an intermediate job that you put in the post-build step and pass to it all the parameters your downstream jobs could possibly need, and then within that job place conditional builds for the real downstream jobs.