Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GitHub Actions - more than one cron

According to the docs, I can use the following syntax for running the CI on a schedule:

on:
  schedule:
    # * is a special character in YAML so you have to quote this string
    - cron:  '*/15 * * * *'

What if I want two crons? What's the syntax for this?

like image 254
Paul Avatar asked May 06 '26 23:05

Paul


2 Answers

Add a cron definiton below the first

on:
  schedule:
    # * is a special character in YAML so you have to quote this string
    - cron: '0 * * * *'
    - cron: '*/10 5 * * *'
like image 101
Krzysztof Madej Avatar answered May 09 '26 11:05

Krzysztof Madej


Responding to @Nasif's question on the accepted answer:

will all the jobs defined in the script run on both these schedules? Or, can I customize which jobs follow which cron?

Yes, I believe they will. However, if you want to run different tasks on different cron's, you can do the following (from the GH Docs):

on:
  schedule:
    - cron: '30 5 * * 1,3'
    - cron: '30 5 * * 2,4'

jobs:
  test_schedule:
    runs-on: ubuntu-latest
    steps:
      - name: Not on Monday or Wednesday
        if: github.event.schedule != '30 5 * * 1,3'
        run: echo "This step will be skipped on Monday and Wednesday"
      - name: Every time
        run: echo "This step will always run"
like image 39
Allen N Avatar answered May 09 '26 13:05

Allen N