Skip to main content
← Back to workflows

How to Create Conditional Build Steps in Jenkins?

conditional-buildstep -
Jenkins Plugin
v.1.4.3
Required Jenkins: v.2.440.3
ID: conditional-buildstep
GitHub Org's stars
Contributors
Categories
CICube banner
The GitHub Actions dashboard helps you spot bottlenecks and optimize your CI pipeline with actionable insights.
Installation with the CLI tool
jenkins-plugin-cli --plugins conditional-buildstep:1.4.3

conditional-buildstep-plugin logo

Conditional Buildstep Plugin

Jenkins plugin that allows conditions to controls step execution


What is Conditional Buildstep Plugin?

This feature allows us to wrap and control the execution of multiple build steps based on a specific condition. It's a great tool for optimizing our job configurations and minimizing redundancy.

First off, we'll need to have both the TokenMacro Plugin and the Run Condition Plugin installed, as these are required for setting up the conditional build steps.

The idea here is pretty straightforward. Instead of having multiple jobs that do nearly the same thing, we can add a conditional buildstep. This acts like a container where you can define a condition that controls whether the included steps should execute or not.

By adopting this approach, we can streamline our processes, making our builds smarter and more efficient. It’s quite useful for maintaining clarity in our pipeline and reducing clutter. Plus, it gives us better control over when and why certain steps are executed, which I believe could be incredibly beneficial for our project management and execution.

What Types of Conditions Can Be Managed in Conditional BuildSteps?

Enhancing our pipeline flexibility with Conditional BuildSteps, which are controlled by various conditions defined by the Run Condition Plugin. Here’s a breakdown of some key features and how we can use them:

  1. Missing Builder Issue: Sometimes, you might not find the builder you want in the conditional build step dropdown. This usually means the builder doesn't have a @DataBoundConstructor or its Descriptor doesn’t extend hudson.tasks.BuildStepDescriptor. For those of us not deep into programming – it simply means the plugin hasn’t been updated to comply with the latest Jenkins coding standards. Without these updates, our conditional buildstep plugin won’t be able to interact with it.

  2. Conditional Step (Single): This build step lets you choose any single build step and apply a condition to decide if it should execute. It’s quite handy for streamlining processes.

  3. Freedom to Re-order: In the single-step setup, steps can be reordered independently, unlike in the multiple-step scenario where reordering is restricted to within the steps of that group. This feature also allows adding new steps in between existing ones, which could either always run or operate under a different condition than the adjacent steps.

  4. Moving Steps Between Conditions: If we’re using two conditions (via EnvInject) to control several steps, it’s easy to switch a single step to the other condition. In the multiple-step setup, all steps share the same condition, so changing conditions might require deleting and then re-adding the step under the new condition.

  5. Multiple Steps Under a Single Condition (EnvInject): We can configure multiple build steps to operate based on a single condition evaluation. By setting up a 'Inject environment variables' action via the EnvInject Plugin and defining a variable in the 'Properties Content', like CONDITION_X=y, all subsequent steps can be controlled with this condition using ${ENV,var="CONDITION_X"}.

These features provide us substantial control over our build process, allowing for more tailored and efficient workflows. It would be great to hear your thoughts on integrating these into our current system!

Monitoring GitHub Actions Workflows

CICube is a GitHub Actions monitoring tool that provides you with detailed insights into your workflows to further optimize your CI/CD pipeline. With CICube, you will be able to track your workflow runs, understand where the bottlenecks are, and tease out the best from your build times. Go to cicube.io now and create a free account to better optimize your GitHub Actions workflows!

CICube GitHub Actions Workflow Duration Monitoring