Why use Conditional step (single)?

Skip to end of metadata
Go to start of metadata

The Conditional step (single) keeps the build flexible at the expense of screen space and extra configuration

Below are some pros and cons

This is just one man's point of view (me, Bap)
IMHO, the reduction in space in the GUI is a very compelling reason to use multiple build steps with the same condition - but, is it worth losing the flexibility?
If you only ever put one build step into the Conditional step (multiple), the result is exactly the same as using the Conditional step (single), and the pros and cons below will stand.
Of course, if we provide more utils/ scripts to move the configured build steps around, then we could make the multiple steps more flexible (tho. not directly from the job config page).
Always use always
As with the Flexible Publish Plugin, if you always add your build steps inside a Conditional step, then you can easily disable and re-enable the build step without losing the configuration (switch between Always and Never).
If you have more than one build step within the conditional step, then you will not be able to disable a single build step independantly.
Freedom to re-order
As there is only one build step within the builder, they can all be re-ordered independantly - in the multiple step, they can only be re-ordered within that step.
This also gives the ability to add build steps in the middle of the current list of steps, where the new step may run on every build, or use a different condition from the steps surrounding it.
Obviously, the Conditional step (multiple) itself can be moved around.
Move a step from one condition to another
If you have several steps that are controlled by two conditions (via EnvInject), then you can easily swith the boolean condition for a single step to use the other condition.
With the multiple, all contained steps use the same condition, so again the step would have to be deleted and then added to the other conditional step.
Multiple steps can still be controlled by a single condition (EnvInject)
You can still run multiple build steps based on the result of a single evaluation of a run condition.
Configure a run condition and in the action choose 'Inject environment variables' provied by the EnvInject Plugin.
In the 'Properties Content' set a variable that will evaluate to true by the Boolean run condition e.g. CONDITION_X=y
Now, for all the build steps that you want to run depending on that condition, use the Boolean run condition with ${ENV,var="CONDITION_X"}
Multiple steps can still be controlled by a single condition (EnvInject)
This still requires extra configuration, and even an extra build step.
GUI space
Many Conditional step (single) build steps will take up a very large area of the configure page which can make the configuration more difficult to read.



Move current buildsteps inside conditional steps

To move all of the current build steps within a freestyle project into Conditional step (single) you can call a utility method from the script console.
The project build will not be affected in any way (other than some extra text in the build console), as the order of the build steps is preserved, and all of the run conditions will be 'Always'.
Build steps that cannot be moved into a conditional step will not be moved.

From Manage Jenkins, Script console, enter the following to update a project called 'My Project'

import static org.jenkinsci.plugins.conditionalbuildstep.singlestep.JobUpdater.*

def job = hudson.model.Hudson.instance.getItem('My Project')
updateBuilders job

After running, go to the configure page, check everything looks ok, then save the configuration.

You can now easily enable and disable the build steps without losing the configuration.

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.