Schedule a workflow programatically

Is it possible to schedule a workflow with a variable or dynamic value? I’d like to be able to set the cron for a workflow via a rest api call.

I imagine using something like the following:

on:
  schedule:
    - cron: ${{ github.event.inputs.cron }}

But of course there’s no event to provide inputs in this example. I thought maybe I could use env context instead, but according to the docs:

You can only use the env context in the value of the with and name keys, or in a step’s if conditional.

If you have any thoughts on setting a scheduled workflow via a rest api call, I’d love to hear them.

Hi @cwgw,

Glad to see you in Github Community Forum!

Dynamic schedule setting is not supported, you cannot dynamically set the value.

As an alternative, you can try to update the schedule setting and push to repository.
Two options here:

  1. Directly update cronsetting via git command.
  2. If you’d like to use rest api, you can use repository_dispatch event, add the cornsetting in the payload value, trigger repository_dispatch event to update the cornsetting.
    My workflow shows the cornsetting value is updated.
    https://github.com/weide-zhou/schedulewf1/runs/868756211?check_suite_focus=true#step:5:9
    image

Thanks

1 Like

Thank you for your response @weide-zhou. I’ll consider implementing your solution in my project.

Cheers.

1 Like