Conditional executions

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.

Conditional executions in pipelines

Pipelines can be run in three trigger modes:

  1. On events – e.g. on a push to the selected branch.
  2. Manually – triggered manually by the user.
  3. On schedule – on a selected time interval.

Each mode lets you select the code scope in which the pipeline operates:

  1. Branch
  2. Tag
  3. Wildcard
  4. Codeless (manual and on schedule only)

All these settings combined allow you to configure pipelines for a wide variety of use cases: from manual releases to the production server, to deployments triggered by a specific phrase in the commit message. Below you can will instructions for different conditions.

Run for specific branch

This setting is most commonly used in deployment pipelines. For example, deployments to the Production server are usually made from the master branch. Assigning the pipeline to 'master' will make Buddy only upload changes from that branch:

Pipeline settings configurationPipeline settings configuration

Unless you have implemented a fully-working Continuous Deployment process into your workflow, we strongly recommend running all production pipelines in manual mode.

Test all changes in repo

In this use case, Buddy acts as a 'classic' CI server that automatically tests new revisions from all branches in the repository.

Configuration

  1. Trigger: On events
  2. Event: Git push
  3. Code scope: Wildcard
  4. Wildcard match: refs/heads/*

Pipeline with wildcard trigger modePipeline with wildcard trigger mode

Run on tag push

Upon finishing a development milestone, an application usually receives a new tag. In Buddy, you can create a pipeline that runs only if a new tag is created or pushed to the repo.

Configuration

  1. Trigger: On events
  2. Event: Git push / Git create branch or tag
  3. Code scope: Tag

Pipeline with tag trigger modePipeline with tag trigger mode

Run for all branches except master

Buddy supports Regex that lets you create patterns for your pipelines. For example, entering (^((?!master$).)*$) for the pattern will force the pipeline to run for all branches except the master branch.

  1. Trigger: On events
  2. Event: Git push
  3. Code scope: Wildcard
  4. Wildcard match: (^((?!master$).)*$)

Pipeline with regex wildcard trigger modePipeline with regex wildcard trigger mode

Run all/only newest execution in pipeline

By default, a pipeline cannot be undergoing more than one execution at a time. If another user triggers a pipeline that's already in progress, the second execution will be queued and will not begin until the first one is over. If there are more executions in the queue (for example 5), Buddy will only run the last execution (5th) and skip the previous ones (1st-4th).

You can disable it by checking Run every queued execution in the pipeline settings – for example, if you want to check the status of all commits on GitHub:

Pipeline runtime conditionsPipeline runtime conditions

If the pipeline is assigned to a wildcard, then only the executions within the same branch are skipped. For example, if you have a pipeline with 1 execution on the master branch and 3 executions on the staging branch queued, Buddy will run the execution for master and skip the 2 executions for stage.

Conditional executions in actions

The conditions listed here can be applied to the entire pipeline by going to the SettingsRun if tab of the desired pipeline.

Run on change in path

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.

Condition: run on change in pathCondition: run on change in path

You can also expand the condition to any update in the repository by setting

if (changeset is not "empty")

Run depending on result of previous action

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

Example action with variable exportExample action with variable export

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

Condition: run if variable has expected valueCondition: 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 a new version on the Slack channel:

Pass Arguments action settingsPass Arguments action settings

Then, set a condition in the Slack action to check if the answer was positive:

if ($sendNotification is "true")

Condition: run if parameter is set to trueCondition: 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:

Pass arguments windowPass arguments window

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 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_EXECUTION_BRANCH as the condition variable in the target action:

if ($BUDDY_EXECUTION_BRANCH is "branch_name")

Condition: run if branch is masterCondition: run if branch is master

Run only if pipeline is executed by specific person

Although Buddy features customizable permissions for pipelines, you can also use the $BUDDY_INVOKER_ID variable to restrict access to individual users. This is especially useful for workspaces in which developers have access to all projects by default.

if ($BUDDY_INVOKER_ID is "number")

Condition: run if invoker is user #16Condition: run if invoker is user #16

The user ID (number) is displayed in the URL on the user profile page: http://app.buddy.works/WORKSPACE_URL/profile/USER_ID

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_EXECUTION_REVISION_MESSAGE contains "phrase")

Condition: run if commit message contains deployCondition: run if commit message contains deploy

Get Started

Sign up for free and deploy your project in less than 10 minutes.