Issue
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
Solution
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: Assignment 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.
Answered By - Alejandro Herrera
Answer Checked By - Mildred Charles (JavaFixing Admin)