Conditional runs

Success
Pipelines and actions can be configured to run on specific conditions. Buddy gives developers full flexibility towards what, where and when should be run, letting you cover even the most sophisticated delivery workflows.
Warning
The conditions listed in this article can be applied to the entire pipelines and/or individual actions – except for Run if action status is/is not which can be used only in actions.

Adding conditions

Actions

To add conditions to actions, go to the Conditions tab in the specific action:

Image loading...Trigger conditions in action

Pipelines

To add a condition to the pipeline, go to the pipeline settings and switch to the Run if tab:

Image loading...Trigger conditions in pipeline

Hint
Buddy also features multi trigger conditions using logical strings connected with OR and AND, e.g.: Image loading...Multi-condition trigger

Run on change in path

You can configure pipelines to run only when changes occur in specific paths of your repository. This feature is particularly useful when you want to trigger a build or deployment process only when certain files or directories are modified.

Certain actions can be skipped if they are not used to speed up pipeline execution. In other words, if you have an action that compiles your assets, you can skip it if there were no changes in the path that requires compilation. For example, upon setting

if (changeset contains "assets/")

the action or pipeline will be run only if there were changes to the assets path in the repository.

Image loading...Condition: run on change in path

Tip
You can also expand the condition to any update in the repository by setting: if (changeset is not "empty")

Run depending on the triggering user

Although Buddy features customizable permissions for pipelines, you can also use conditions to further restrict run permissions to individual users or groups. This is especially useful for workspaces in which developers have default access to all projects.

By defining conditions, you can specify that a pipeline should only run if it is triggered by a specific user. On the other hand, you can also prevent a pipeline from running for a certain user. This ensures that the pipeline will not be triggered by that user, even if they have the necessary permissions.

Additionally, you can restrict the ability to run the pipeline for users belonging (or not) to a specific group.

default
if (invoker is/is not "user_name") if (invoker is in group/is not in group "group_name")

Image loading...Condition: run depending on triggering user

Run depending on the day and time

Conditional executions also offer the ability to schedule pipelines and/or actions to run at specific days and times. This feature is particularly useful when you want to limit the execution of certain sensitive processes to business hours or specific time zones.

if (day is "day" in "timezone_name") if (hour is "hour" in "timezone_name")

Image loading...Condition: run depending on day and time

Run if the pipeline passed with the same revision

With this option, you can configure a pipeline to run only if the selected pipeline run for this revision has been successful. The most common use-case for this condition is to ensure that your production pipeline doesn't run if the testing pipeline for the same revision failed to pass beforehand.

if ("pipeline_name" in "project_name" passed with the same revision)

Image loading...Condition: run if pipeline passed with the same revision

Run depending on the action status

Hint
The following condition can be set in actions only. To add it, go to the Conditions tab in the action.

This condition allows you to determine whether an action should be triggered based on the status of another action. The feature lets your pipeline respond intelligently to the outcome of previous actions, e.g. by sending different notifications depending on the action that failed.

if ("action_name" status is success / failed / skipped / suppressed)

Image loading...Condition: run depending on the action status

Run depending on ENV VAR value

Variables are extremely handy when you need to be precise about what you want to run and when. Here you can use Buddy's default variables, parameters defined in the Pass Params action, and your own custom variables.

Run depending on output of previous action

  1. Add a custom variable (e.g. $OUTPUT) and set it as settable.
  2. Add a container action and enter the condition that will define the value of the variable, for example:
bash
export OUTPUT=expected_value $$

Image loading...Example action with variable export

  1. Add another action and set the condition to check if the value of the variable is correct:
if ($OUTPUT is "expected_value")

Image loading...Condition: run if variable has expected value

Run depending on parameters passed on pipeline run

The Pass Arguments action allows you to create and pass parameters as environment variables during pipeline execution. This way you change the behavior of a pipeline that's already in progress.

For example, you can set a true/false parameter asking if you want to notify your clients of the new version on your Slack channel:

Image loading...Pass Arguments action settings

The second step is setting a condition in the Slack action to check if the answer was positive:

if ($sendNotification is "true")

Image loading...Condition: run if parameter is set to true

Once triggered, the action will ask you to select the argument that will be passed to the Slack notification:

Image loading...Pass arguments window

Run only for specific branch

If you have a wildcard pipeline and want to run an action on changes in a specific branch (e.g. integration tests on the master branch), you can use $BUDDY_RUN_BRANCH as the condition variable in the target action:

if ($BUDDY_RUN_BRANCH is "branch_name")

Image loading...Condition: run if branch is master

Run only if commit message contains specific phrase

The last example of variable-based conditions is listening for a keyword in the commit message. This is useful when you push some code to the repository, but don't want to trigger the deployment just yet:

if ($BUDDY_RUN_COMMIT_MESSAGE contains "phrase")

Image loading...Condition: run if commit message contains deploy

Last modified on Oct 29, 2024