问题描述
我正在尝试使用自托管的 Windows-VM 运行 west 以进行 repo 管理,使用 python 运行一些脚本,并使用 git 推回 repo。
工作是使用来自 LoggingString
的 python 作为工件生成文件以签入 repo-A
。我不得不使用 Windows,因为文件生成工具只适用于 Windows。
我有一个自托管的构建代理设置,并且能够在其上运行 github 操作。
在 VM 端,这些是相关命令的路径(显示它们已正确添加到 $PATH)
repo-B
VM 的执行策略设置为:
PS C:\TouchGFXProjects\wallSwitch-gui-hesPrototype-480-272> gcm west; gcm tgfx.exe; gcm python; gcm git
CommandType Name Version Source
----------- ---- ------- ------
Application west.exe 0.0.0.0 C:\Users\tgfx\AppData\Local\Programs\Python\python39\Scripts\west.exe
Application tgfx.exe 4.16.1.0 C:\TouchGFX\4.16.1\designer\tgfx.exe
Application python.exe 3.9.515... C:\Users\tgfx\AppData\Local\Programs\Python\python39\python.exe
Application git.exe 2.31.1.1 C:\Program Files\Git\cmd\git.exe
当从虚拟机本身的 PowerShell 执行时,所有脚本和执行步骤都运行良好。
但是当我调用 github runner 时,行为表明它不知道可执行文件在哪里,尽管它在 PS C:\Windows\system32> Get-ExecutionPolicy -List
Scope ExecutionPolicy
----- ---------------
MachinePolicy Undefined
UserPolicy Undefined
Process Undefined
CurrentUser Undefined
LocalMachine Bypass
中是已知的(参见下面的调试输出)。
github 运行脚本:
$PATH
在 github runner 上运行时,echo ${env:PATH} 命令显示:
name: CI
on:
workflow_dispatch:
pull_request:
branches:
- master
- 'feature/**'
jobs:
# Test-path access using powerShell shell
test-path-powerShell:
runs-on: [self-hosted,Windows,X64,touchGFX]
steps:
- name: display the path
run: echo ${env:PATH}
shell: powershell
continue-on-error: true
- name: Check that we kNow where python is
run: gcm python
shell: powershell
continue-on-error: true
- name: Test calling "python.exe --version" via powershell
run: python.exe --version
shell: powershell
continue-on-error: true
- name: Test calling "python.exe --version" via powershell (abs path)
run: C:\Users\tgfx\AppData\Local\Programs\Python\python39\python.exe --version
shell: powershell
continue-on-error: true
这意味着它应该有 python.exe 的位置
但是,所有尝试访问它的命令(即使使用绝对路径)都会返回如下错误:
Run echo ${env:PATH}
C:\TouchGFX\4.16.1\designer;C:\Users\tgfx\AppData\Local\Programs\Python\python39\;C:\Users\tgfx\AppData\Local\Programs\Python\python39\Scripts\;C:\Users\tgfx\AppData\Local\Programs\Python\python39\Lib\site-packages;C:\Program Files\Git\cmd;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Windows\ServiceProfiles\NetworkService\AppData\Local\Microsoft\WindowsApps
我还尝试将 python 附加到 $GITHUB_PATH 中:
Run gcm python
gcm : The term 'python' is not recognized as the name of a cmdlet,function,script file,or operable program. Check
the spelling of the name,or if a path was included,verify that the path is correct and try again.
At C:\actions-runner\_work\_temp\c19697cd-d5e0-4102-a7b6-5f357f82aa91.ps1:2 char:1
+ gcm python
+ ~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (python:String) [Get-Command],CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException,Microsoft.PowerShell.Commands.GetCommandCommand
但这只是扩展了 echo ${env:PATH} 的输出,并且在执行时仍然会导致相同的错误。
我错过了什么?
感谢大家的时间。
解决方法
在我的设置中,缺少的部分是 Github Action Runner Service
的访问权限。将运行程序安装为服务时使用的默认 NT AUTHORITY\NETWORK SERVICE
不起作用。我测试了将服务的权限更改为 Local Service
和 Local System
并发现 Local System
有效。
更改权限时需要重启服务才能生效。
在 github runner 工作流程中,您可以使用来自 powershell 的 whoami
命令验证设置。