简体   繁体   中英

Azure Pipelines does not recognize mvn in self hosted agent

I have already installed maven on my own agent and when I run the command mvn -v from putty I get this output:

Maven home: /opt/maven Java version: 1.8.0_292, vendor: Private Build, runtime: /usr/lib/jvm/java-8-openjdk-amd64/jre Default locale: en_US, platform encoding: UTF-8 OS name: "linux", version: "4.15.0-1071-azure", arch: "amd64", family: "unix"

With this output I make sure maven is installed correctly and has environment variables set correctly.

But when I run maven tasks on this agent from azure devops I get the following error message :

##[error]Unhandled: Unable to locate executable file: 'mvn'. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also check the file mode to verify the file is executable.

I tried running only an azure devops bash task that would execute the command mvn -v and I get the following error :

mvn: command not found

I would appreciate your support as I am sure Maven is well installed and configured but for some reason azure devops does not recognize these commands

I tried many ways but none worked.

finally it occurred to me to assign the environment variables from azure devops.

First, I tried creating a bash task that would run the command export M2_HOME=/opt/maven but it didn't work.

Then i tried azure own instructions: echo "##vso[task.setvariable variable=M2_HOME]/opt/maven" and it worked fine.

The concrete solution was to create two tasks before the maven tasks that assigned all the necessary environment variables, as follows:

在此处输入图像描述

tasks run the following commands:

在此处输入图像描述

在此处输入图像描述

NOTE: A ssignment does not work in a single task because the second task uses a variable that is assigned in the first. if it is to define a variable and use it in the same task it will not work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM