'Mvn is not recognized as a command on Github Actions on Windows a self hosted runner
I set up a simple Github Actions workflow simply to check if my self-hosted Windows Virtual Machine is able to recognize the installed java/git/maven versions.
Versions in the Virtual Machine:
- Microsoft Windows 64 bit
- Java version: jdk1.8.0_202
- Maven version: 3.8.5
Java and Git are correctly recognized however the step checking for maven version fails:
mvn -version
it fails with the following log:
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\_temp\03b2e64a-9586-4937-b61c-90e0bb0a5d9c.ps1:2 char:1
+ mvn -version
+ ~~~
+ CategoryInfo : ObjectNotFound: (mvn:String) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : CommandNotFoundException
Error: Process completed with exit code 1.
Below how I set up the environmental variables on the machine:
Environment Variable Screenshot
On the machine mvn command is recognized without any problems, the issue only happens when running the Github workflow yaml. Below the .yaml script also with different attempts to set the enviroment variable from the script itself:
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-runner\apache-maven-3.8.5\bin\mvn -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-runner\apache-maven-3.8.5\bin'
# 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-runner\apache-maven-3.8.5\bin'
- name: set PATH Maven
run: echo "C:\action-runner\apache-maven-3.8.5\bin" >> $env:GITHUB_ENV
Thanks in advance to anyone suggesting a solution.
Solution 1:[1]
Solved by adding this Actions from the GitHub Marketplace inside the .yml workflow file:
https://github.com/stCarolas/setup-maven https://github.com/marketplace/actions/setup-maven
Solution 2:[2]
I just ran into this with python. I had install it for all users in the windows installer settings. I would try to install for all users and then the service should have maven in scope.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Matteo Barzaghi |
Solution 2 | Jacob Matson |