docs/adrs/1751-runner-job-hooks.md
This ADR details the design changes for supporting custom configurable hooks for on various runner events. This has been a long requested user feature here, here and here for users to have more information on runner observability, and for the ability to run cleanup and teardown jobs.
This feature is mainly intended for self hosted runner administrators.
What we hope to solve with this feature
What we don't think this will solve
Notification Hooks for Runners is limited to self hosted runners, we don't beileve Policy features should beACTIONS_RUNNER_HOOK_JOB_STARTEDACTIONS_RUNNER_HOOK_JOB_COMPLETEDYou can set these variables to the absolute path of a .sh or .ps1 file.
We will execute pwsh (fallback to powershell) or bash (fallback to sh) as appropriate.
.sh files will execute with the args -e {pathtofile}.ps1 files will execute with the args -command \". '{pathtofile}'\"We will not set the standard flags we typically set for runs commands. So, if you want to set pipefail on bash for example, you will need to do that in your script.
We want to ensure the experience for users invoking workflows is good, if hooks take too long, you may feel your job is delayed or broken. So, much like Set Up Job, we will generate two new steps automatically in your job, one for each configured hook:
Set up runnerComplete runnerThese steps will contain all of the output from invoking your hook, so you will have visibility into the runtime. We will also provide information on the path to the hook, and what shell we are invoking it as, much like we do for run: steps.
When running your hooks, some context on your job may be helpful.
GITHUB_ACTION, in which case they will not be setGITHUB_EVENT_PATHShould we expose Commands and Environment Files
Yes. Imagine a scenario where a runner administrator is deprecating a runner pool, and they need to warn users to swap to a different pool, we should support them in doing this. However, there are some limitations:
id as this is not a traditional stepWe will also enable Environment Files to support setup scenarios for the runner environment.
While a self hosted runner admin can set env variables, these apply to all jobs. By enabling the ability to add a path and set an env we give runner admins the ability to do this dynamically based on the workflows environment variables to empower setup scenarios.
These are synchronous hooks, so they will block job execution while they are being run. Exit code 0 will indicate a successful run of the hook and we will proceed with the job, any other exit code will fail the job with an appropriate annotation.
continue-on-errorACTIONS_RUNNER_HOOK_JOB_STARTEDACTIONS_RUNNER_HOOK_JOB_COMPLETED.sh or .ps1 file, which we will execute when Jobs are started or completed.
Set up runner or Complete runner.
always() execute if the env variable is setcontinue-on-error type option on launchtimeout option on launch