Search code examples
continuous-integrationworkflowgithub-actionsgithub-actions-self-hosted-runners

Looking for a way to run a workflow on all self-hosted agents in a pool for Github actions


I’m trying to run a maintenance workflow on all agents. It’s a cleaning job like “docker system prune”. I wish it runs on all self-host agents (about 12 agents) weekly on Sunday night. I noticed that workflows can run with on schedule event. This is great. But I didn’t find a way to make all self-hosted agents to run the workflow. Any suggestions?


Solution

  • I believe that this problem is more about your operating system(s), not about workflows on GitHub side. It might be possible to do as workflow, but then your agents are requiring either to be on host operating system, or have access for Docker socket. (I don't know how you are hosting them). Either way, might be insecure depending on if host is used on something else as well.

    As GitHub docs are stating, you are responsible about your operating system.

    In general, you can schedule maintenance jobs with cron, might be the most used one. How to install it, depends on your operating system.

    To add scheduled work, run command crontab -e, select editor and add line to the end:

    0 3 * * 0 /usr/bin/docker system prune -f to run 03:00 AM Sunday weekly.

    However, if you really want to use workflows, you could read some docs on here. It states, that "Labels allow you to send workflow jobs to specific types of self-hosted runners, based on their shared characteristics." So you could create specific maintenance job for every runner with different label. This requires many scheduled jobs as runners are not intended to launch multiple times for same job.