Multiple event triggers with config

I want to run a given workflow both on push and based on a cronjob.

I assumed this to work:

on:
  - push
  - schedule:
      - cron: '0 0 * * *' # Once per day at midnight

However that throws with:

Invalid type for on

How can I get this to work?

When you want to specify properties for the events you need to specify as a map instead of an array.

on:
  push
  schedule:
      - cron: '0 0 * * *' # Once per day at midnight
6 Likes

When I try the accepted solution, the workflow editor seems to think the syntax is invalid [for having a string inside the yaml mapping vs a key with a trailing colon] (see screenshot).

Is it possible that push here should instead be push:?

I’ve tried using it with the colon in a quick test just now and both the push run and the schedule run executed as expected.

4 Likes

You can use

on:
  push:
    branches:
      - master

  schedule:
    - cron: '*/5 * * * *'

Even though I’m a little late on this one, but yes

on:
  push:
  schedule:
    - cron: '0 0 * * * '

is perfectly valid YAML. It’s all about the nesting. :slight_smile:

2 Likes