name: Scheduled Job
on:
schedule:
- cron: "*/5 * * * *" # Runs every 5 minutes
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened]
branches:
- main
workflow_dispatch: {}
jobs:
scheduled-job:
runs-on: ubuntu-latest
steps:
- name: Print Current Time
run: echo "The current time is $(date)
The above github actions workflow YAML is not triggering for every 5 minutes when I pushed the feature branch and raise a PR
Please guide me the reason why the CRON job is not triggered?
0
not triggering for every 5 minutes when I pushed the feature branch and raise a PR
It does not trigger for a feature branch because the documentation clearly states this:
Scheduled workflows run on the latest commit on the default or base branch. The shortest interval you can run scheduled workflows is once every 5 minutes.
This part should for sure trigger for a push to the main
branch though:
push:
branches:
- main
and that might be redundant with the whole cron schedule. I’m not sure if a scheduled workflow will trigger for commits that have already been verified on push.
Pull request against the main
branch should also automatically trigger without the whole cron part:
pull_request:
types: [opened, synchronize, reopened]
branches:
- main
If none of these trigger, first make sure your default branch really is main
and and not master
. main
is the new default at GH, but your local git installation might still use master
.
See the documentation for more: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#schedule