[英]How to run pre/post job scripts on self-hosted GitHub Actions runner
I am trying to use a Windows Docker container to run GitHub Actions.我正在尝试使用 Windows Docker 容器来运行 GitHub 操作。
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.我之前在一台没有运行 docker 的计算机上成功地完成了这个,所以我认为在 docker 上也应该可以工作。
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.我尝试重新启动 docker 容器。
I have tried restarting the actions runner service.我试过重新启动 actions runner 服务。
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.我是 docker 的新手,所以我想知道我是否对不适用于 docker 的环境变量做错了什么。
How do I get the actions runner to run pre/post job scripts in docker?如何让操作运行器在 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.在actions-runner目录中,找到.env文件,通过添加环境变量对其进行编辑。 Save and restart the runner service.
保存并重启运行器服务。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.