RRe*_*Ret 5 github-for-windows github-actions-runners github-actions-self-hosted-runners
我正在尝试使用自托管的 Windows-VM 来运行 west 进行存储库管理,使用 python 来运行一些脚本,并使用 git 来推送回存储库。
这项工作是使用 python 生成文件repo-A作为工件来签入repo-B。我必须使用 Windows,因为文件生成工具只能在 Windows 上运行。
我有一个自托管构建代理设置,并且能够在其上运行 github 操作。
在VM端,这些是相关命令的路径(表明它们已正确添加到$PATH)
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
Run Code Online (Sandbox Code Playgroud)
VM 的执行策略设置为:
PS C:\Windows\system32> Get-ExecutionPolicy -List
Scope ExecutionPolicy
----- ---------------
MachinePolicy Undefined
UserPolicy Undefined
Process Undefined
CurrentUser Undefined
LocalMachine Bypass
Run Code Online (Sandbox Code Playgroud)
当从虚拟机本身的 powerShell 执行时,所有脚本和执行步骤都运行良好。但是,当我调用 github 运行程序时,该行为表明它不知道可执行文件在哪里,尽管它是已知的$PATH(请参阅下面的调试输出)。
github 运行脚本:
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
Run Code Online (Sandbox Code Playgroud)
在 github runner 上运行时,echo ${env:PATH} 命令显示:
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
Run Code Online (Sandbox Code Playgroud)
这意味着它应该有 python.exe 的位置
但是,尝试访问它的所有命令(即使使用绝对路径)都会返回如下错误:
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
Run Code Online (Sandbox Code Playgroud)
我还尝试将 python 附加到 $GITHUB_PATH :
echo "C:\Users\tgfx\AppData\Local\Programs\Python\Python39" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
Run Code Online (Sandbox Code Playgroud)
但这只是扩展了 echo ${env:PATH} 的输出,并且在执行时仍然导致相同的错误。
我缺少什么?
感谢大家的时间。
在我的设置中,缺少的部分是Github Action Runner Service. 将运行器安装为服务时使用的默认值NT AUTHORITY\NETWORK SERVICE不起作用。我测试了更改服务的权限Local Service,Local System发现这Local System有效。
修改权限后需要重启服务才能生效。
在 github 运行程序工作流程中,您可以使用 powershell 中的命令验证设置whoami。
| 归档时间: |
|
| 查看次数: |
2546 次 |
| 最近记录: |