简体   繁体   中英

How to run pre/post job scripts on self-hosted GitHub Actions runner

Problem

I am trying to use a Windows Docker container to run GitHub Actions.

I want to run scripts before and after the job (eg to clean the directory).

I have successfully done this before on a computer not running docker, so I figured the same should work in docker.

What I have tried

I found here that you can do that using Environment Variables. I used the following two commands in command prompt to set the environment variables.

Pre-Job Script:

setx ACTIONS_RUNNER_HOOK_JOB_STARTED C:\actions-runner-resources\scripts\pre-post-build\pre-run-script.ps1

Post-Job Script:

setx ACTIONS_RUNNER_HOOK_JOB_COMPLETED C:\actions-runner-resources\scripts\pre-post-build\post-run-script.ps1

The scripts do not run.

I have tried restarting the docker container.

I have tried restarting the actions runner service.

I am new to docker, so I am wondering if I am doing something wrong with the environment variables that does not work with docker.

How do I get the actions runner to run pre/post job scripts in docker?

You can safely add them to your environment variable by doing this recommended method;

Inside the actions-runner directory, locate the .env file, edit it by adding your environment variable. Save and restart the runner service.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM