Conditional runs
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...
Pipelines
To add a condition to the pipeline, go to the pipeline settings and switch to the Run if tab:
Image loading...
OR
and AND
, e.g.:
Image loading...
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...
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.
defaultif (invoker is/is not "user_name") if (invoker is in group/is not in group "group_name")
Image loading...
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...
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...
Run depending on the action status
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...
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
- Add a custom variable (e.g.
$OUTPUT
) and set it as settable. - Add a container action and enter the condition that will define the value of the variable, for example:
bashexport OUTPUT=expected_value
$
Image loading...
- Add another action and set the condition to check if the value of the variable is correct:
if ($OUTPUT is "expected_value")
Image loading...
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...
The second step is setting a condition in the Slack action to check if the answer was positive:
if ($sendNotification is "true")
Image loading...
Once triggered, the action will ask you to select the argument that will be passed to the Slack notification:
Image loading...
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...
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...
Last modified on Oct 29, 2024