Mvn在Github Actions上不被识别为命令



我设置了一个简单的Github Actions工作流,只是为了检查我的自托管Windows虚拟机是否能够识别安装的java/git/maven版本。

虚拟机版本号:

  • Microsoft Windows 64位
  • Java版本:jdk1.8.0_202
  • Maven版本:3.8.5

Java和Git被正确识别,但是maven版本的步骤检查失败:

mvn -version

失败,输出如下日志:

mvn : The term 'mvn' 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:action-runner_work_temp3b2e64a-9586-4937-b61c-90e0bb0a5d9c.ps1:2 char:1
+ mvn -version
+ ~~~
+ CategoryInfo          : ObjectNotFound: (mvn:String) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : CommandNotFoundException

Error: Process completed with exit code 1.

下面是我在机器上设置环境变量的方法:

环境变量截图

在机器上mvn命令被识别没有任何问题,问题只发生在运行Github工作流yaml时。下面的.yaml脚本也用不同的方法从脚本本身设置环境变量:

name: CI
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

workflow_dispatch:

jobs:
build:
runs-on: [self-hosted, selenium-1]
steps:
- uses: actions/checkout@v3
# Attempt 1: FAILS with mvn not recognized log
- name: Check Maven version
run: mvn -version
# Attempt 2: DOES NOT FAIL but it also doesn't do anything (tried other mvn commands and nothing happened)
- name: Check Maven Version
run: C:action-runnerapache-maven-3.8.5binmvn -version
# Attempt 3 set Maven as env variable with powershell and FAILS with mvn not recognized log
- name: Set maven path as Env variable
run: $Env:GITHUB_ENV += ';C:action-runnerapache-maven-3.8.5bin'
# after Attempt 3 launched the mvn command to check if it worked but still failed
- name: Check Maven version
run: mvn -version
# Attempt 4 try to set PATH variable once in the workflow with following log:
# Error: Unable to process file command 'env' successfully.
# Error: Invalid environment variable format 'C:action-runnerapache-maven-3.8.5bin'
- name: set PATH Maven
run: echo "C:action-runnerapache-maven-3.8.5bin" >> $env:GITHUB_ENV

提前感谢任何提出解决方案的人。

我刚刚在python中遇到了这个问题。我必须在windows安装程序设置中为所有用户安装它。我会尝试为所有用户安装,然后服务应该有maven的范围。

通过在.yml工作流文件中添加GitHub Marketplace中的此操作来解决:

https://github.com/stCarolas/setup-mavenhttps://github.com/marketplace/actions/setup-maven

相关内容

  • 没有找到相关文章

最新更新