首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Windows上的github runner在PowerShell上找不到可执行文件

Windows上的github runner在PowerShell上找不到可执行文件
EN

Stack Overflow用户
提问于 2021-05-19 05:33:37
回答 1查看 425关注 0票数 0

我正在尝试使用自托管的Windows-VM来运行west来进行repo管理,使用python来运行一些脚本,并使用git来推送回repo。

工作是使用repo-A中的python作为检入repo-B的工件来生成文件。我不得不使用Windows,因为文件生成工具只能在Windows上运行。

我有一个自托管的构建代理设置,并且能够在其上运行github操作。

在VM端,这些是相关命令的路径(显示它们已正确添加到$PATH)

代码语言:javascript
复制
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

VM的执行策略设置为:

代码语言:javascript
复制
PS C:\Windows\system32> Get-ExecutionPolicy -List
        Scope ExecutionPolicy
        ----- ---------------
MachinePolicy       Undefined
   UserPolicy       Undefined
      Process       Undefined
  CurrentUser       Undefined
 LocalMachine          Bypass

当从VM本身上的powerShell执行时,所有脚本和执行步骤都运行良好。但是当我调用github运行器时,行为表明它不知道可执行文件在哪里,尽管它在$PATH中是已知的(参见下面的调试输出)。

github runner脚本:

代码语言:javascript
复制
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

在github运行器上运行时,echo ${env:PATH}命令显示:

代码语言:javascript
复制
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.exe的位置

但是,尝试访问它的所有命令(即使使用绝对路径)都会返回如下错误:

代码语言:javascript
复制
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

我还尝试使用以下命令将python附加到$GITHUB_PATH:

代码语言:javascript
复制
echo "C:\Users\tgfx\AppData\Local\Programs\Python\Python39" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append

但这只是扩展了echo ${env:PATH}的输出,并且在执行时仍然会导致相同的错误。

我遗漏了什么?

感谢大家的宝贵时间。

EN

回答 1

Stack Overflow用户

发布于 2021-05-25 02:41:45

在我的设置中,缺少的部分是Github Action Runner Service的访问权限。将runner作为服务安装时使用的默认NT AUTHORITY\NETWORK SERVICE不起作用。我测试了将服务的权限更改为Local ServiceLocal System,发现Local System工作正常。

您需要在更改权限时重新启动服务才能使其生效。

在github runner工作流中,您可以使用powershell中的whoami命令来验证设置。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67594211

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档