简体   繁体   English

如何在自托管 GitHub Actions runner 上运行前/后作业脚本

[英]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.我正在尝试使用 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 上也应该可以工作。

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.我尝试重新启动 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.

相关问题 使用自托管证书签署Windows可执行文件 - Signing Windows Executables with self-hosted certificate 在自托管 windows azure devops 代理上运行 docker 容器的权限 - Permissions to run docker container on self-hosted windows azure devops agent 如何在 Github 操作上执行 MSI 文件(Windows 最新运行程序) - How to execute MSI file on Github Actions (windows-latest runner) 如何使用自托管ASP.NET Core 2应用程序(httpsys)进行HTTPS(SSL) - How to HTTPS (SSL) with self-hosted ASP.NET Core 2 app (httpsys) 没有管理权限的localhost上的自托管REST API - Self-hosted REST API on localhost without administrative privileges WCF自托管:匿名身份验证方案禁止使用HTTP请求 - WCF self-hosted: http request forbidden for authentication scheme anonymous GitHub 操作:在 wihdows 上运行 golint - GitHub Actions: Run golint on wihdows 通过Internet访问Azure虚拟机上的自托管WCF服务 - Access to a self-hosted WCF service on azure virtual machine over the Internet 使用net.tcp时,MONO WCF自托管服务对获取对等方的连接重置 - MONO WCF Self-Hosted Service Pair getting Connection reset by peer when using net.tcp Rundeck - 我为运行 python 脚本而创建的作业调用了不同的 python - Rundeck - The job that I created to run python scripts calls a different python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM