On environment event

View as Markdown

Environment event triggers let you run a pipeline when an environment is created or deleted. Buddy starts all pipelines whose trigger matches the environment - for example, provision a database and DNS entry for every new preview-* environment, or remove them when the environment is deleted.

There are two environment event types:

  • Environments: Created - triggered when a new environment is created.
  • Environments: Deleted - triggered when an environment is deleted.

Configure trigger

  1. Open your pipeline and go to the Workflow tab.
  2. Click + in the Triggers section and select Created or Deleted in the Environments group.

    Image loading...Environments group in the trigger dropdown

  3. Pick the environments that should start the pipeline, or tick All environments.
  4. Click Apply.

The trigger appears in the Triggers section with the selected environments and matching filters:

Image loading...Artifact and environment triggers in the pipeline workflow

Filters

The trigger fires when the environment matches at least one of the entries in the popup.

  • Environments - existing environments in the project. Tick the ones that should start the pipeline.
  • All environments - reacts to every environment. In YAML this is stored as '*'.
  • Add or manage matching filters - opens a modal where you define patterns instead of picking specific environments:
    • ID - an environment identifier pattern with wildcards, e.g. preview-*.
    • Scope - where the environment lives: Any, Workspace, or Project.
    • Tags - tags the environment must have.

Specific environments, All environments, and matching filters can be combined in a single trigger. Created and Deleted are separate triggers with their own filters.

YAML

The event types are ENVIRONMENT_CREATE and ENVIRONMENT_DELETE. The environments list accepts '*' for all environments, specific environment identifiers, and objects with environment, scope, and tags:

yaml
- pipeline: "Provision preview" refs: - "refs/heads/master" events: - type: "ENVIRONMENT_CREATE" environments: - environment: "preview-*" scope: "PROJECT" actions: - action: "Create database" type: "BUILD" docker_image_name: "library/ubuntu" docker_image_tag: "22.04" commands: |- ./scripts/create-preview-db.sh

scope takes ANY, WORKSPACE, or PROJECT. This pipeline tears down resources for any deleted environment tagged preview:

yaml
- pipeline: "Tear down preview" refs: - "*" events: - type: "ENVIRONMENT_DELETE" environments: - environment: "*" tags: - "preview" actions: - action: "Drop database" type: "BUILD" docker_image_name: "library/ubuntu" docker_image_tag: "22.04" commands: |- ./scripts/drop-preview-db.sh
Info
Pair the Created trigger with a matching Deleted trigger in a second pipeline so that everything provisioned for an environment is removed when the environment goes away.

See also

Last modified on Sep 22, 2026