Skip to main content
In addition to configuring triggers via UI, you can also configure triggers in code. You can either manually define the triggers in code or you can go to the triggers detail page in the UI and click the button labeled Save trigger in code on the left side panel to store the current trigger’s settings to code.

Create and configure triggers

Here are the steps to create and configure triggers via code:
  1. Create a triggers.yaml file under your pipeline folder. The file path should be pipelines/[pipeline_uuid]/triggers.yaml.
  2. Enter your trigger configs into the triggers.yaml file.
    1. Content structure
      triggers:
      - name: test_trigger
        schedule_type: time
        start_time: 2023-01-01
        status: active
      - name: xxx
        ...
      - name: xxx
        ...
      
    2. Required trigger fields
      1. name: Unique identifier of the trigger
      2. schedule_type: time, api, or event
      3. schedule_interval: @once, @hourly, @daily, @weekly, @monthly, @always_on, or Cron syntax(* * * * *)
      4. start_time: The start time of the trigger (e.g. 2023-01-01)
    3. Optional trigger fields
      1. status: active or inactive
      2. variables: A dictionary of variables that’s associated with the trigger
      3. sla: SLA in seconds
      4. settings: a dictionary of advanced settings
        1. skip_if_previous_running: true/false
        2. allow_blocks_to_fail: true/false
        3. create_initial_pipeline_run: true/false
      5. envs: The environments that the trigger runs in.
        • If envs is not set or empty, the trigger will run in all environments.
        • The environment of the Mage app is set via the ENV environment variable.
        • OSS: Only supports dev, staging, prod, test.
        • Mage Pro: Supports any value, which must match the ENV environment variable.
  3. Save the triggers.yaml file. The trigger configs will be synced to the triggers UI shortly.

Example triggers config:

triggers:
- name: test_example_trigger
  schedule_type: time
  schedule_interval: "@daily"
  start_time: 2023-01-01
  status: active
- name: test_example_trigger_2
  schedule_type: time
  schedule_interval: "@hourly"
  start_time: 2023-03-01
  status: inactive
- name: test_example_trigger_with_extra_settings
  schedule_type: time
  schedule_interval: "@hourly"
  start_time: 2023-03-01
  status: inactive
  settings:
    skip_if_previous_running: true
    allow_blocks_to_fail: true
  envs:
  - prod
  - dev

Modify triggers

If an existing trigger is configured in the yaml file, any updates to it through the UI will also update trigger config in the yaml file. If you modify the trigger settings directly in the yaml, it will automatically update the trigger in the UI. The new trigger configs are synced to the triggers in UI.

Delete triggers

The triggers.yaml file is synced into the database automatically, but deletions work differently:
  • Deleting triggers completely: Removing a trigger from the yaml file won’t delete it from the database. You will need to delete the trigger in the UI.
    • In the Pipeline triggers table (/pipeline/[pipeline_uuid]/triggers), click the trash can icon.
    • In Mage Pro, right-click on the trigger row and click Delete.
    This ensures the trigger is removed both from the database and from the pipeline’s triggers.yaml config file.
  • Alternative to deletion: Instead of deleting, you can update the trigger status in the yaml file (e.g. set status: inactive). Status changes are automatically synced to the database and UI.
I