I am running the example of javascript github actions and it works just fine when I have
on: [push]
but not when I have
on:
schedule:
- cron: '*/5 * * * *'
I expect the github action to run every 5 minutes but it doesn't seem to run at all.
Here is the rest of my code for reference
.github/worflows/main.yml
on:
schedule:
- cron: '*/5 * * * *'
jobs:
hello_world_job:
runs-on: ubuntu-latest
name: A job to say hello
steps:
- name: Hello world action step
id: hello
uses: StephenVNelson/website/@3-experiment-with-actions
with:
who-to-greet: 'Mona the Octocat'
# Use the output from the `hello` step
- name: Get the output time
run: echo "The time was ${{ steps.hello.outputs.time }}"
./action.yml
name: 'Hello World'
description: 'Greet someone and record the time'
inputs:
who-to-greet: # id of input
description: 'Who to greet'
required: true
default: 'World'
outputs:
time: # id of output
description: 'The time we greeted you'
runs:
using: 'node12'
main: './github-actions/main.js'
./github-actions/main.js
const core = require('@actions/core');
const github = require('@actions/github');
try {
// `who-to-greet` input defined in action metadata file
const nameToGreet = core.getInput('who-to-greet');
console.log(`Hello ${nameToGreet}!`);
const time = (new Date()).toTimeString();
core.setOutput("time", time);
// Get the JSON webhook payload for the event that triggered the workflow
const payload = JSON.stringify(github.context.payload, undefined, 2)
console.log(`The event payload: ${payload}`);
} catch (error) {
core.setFailed(error.message);
}
You can configure your workflows to run when specific activity on GitHub happens, at a scheduled time, or when an event outside of GitHub occurs.
To run jobs sequentially, you can define dependencies on other jobs using the jobs. <job_id>. needs keyword. Each job runs in a runner environment specified by runs-on .
Go to your GitHub repository (create one if required). Go to the Actions tab and create a new action workflow. Add your Cron schedule and task to it. Commit the change.
These three steps are given below. Create github action. Generate a personal access token. Create a http request.
As mentioned in the GitHub documentation about Scheduled events
The schedule event can be delayed during periods of high loads of GitHub Actions workflow runs. High load times include the start of every hour. To decrease the chance of delay, schedule your workflow to run at a different time of the hour.
Read further : No assurance on scheduled jobs?
You won't be able to schedule it for every 5 minutes as the "shortest interval you can run scheduled workflows is once every 15 minutes":
https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#schedule
Change it to '*/15 * * * *' and you'll be fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With