[英]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,当我从 putty 运行命令
mvn -v
时,我得到了这个 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"
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”,版本:“4.15.0-1071-azure”,arch:“amd64”,家族:“unix”
With this output I make sure maven is installed correctly and has environment variables set correctly.有了这个 output ,我确保 maven 安装正确并且环境变量设置正确。
But when I run maven tasks on this agent from azure devops I get the following error message :但是,当我从 azure devops 在此代理上运行 maven 任务时,我收到以下错误消息:
##[error]Unhandled: Unable to locate executable file: 'mvn'.
##[错误]未处理:无法找到可执行文件:'mvn'。 Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable.
请验证文件路径是否存在,或者该文件是否可以在 PATH 环境变量指定的目录中找到。 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 :我尝试仅运行 azure devops bash 任务,该任务将执行命令
mvn -v
,我收到以下错误:
mvn: command not found
mvn:找不到命令
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感谢您的支持,因为我确信 Maven 已安装和配置良好,但由于某种原因 azure devops 无法识别这些命令
I tried many ways but none worked.我尝试了很多方法,但都没有奏效。
finally it occurred to me to assign the environment variables from azure devops.最后我想到从 azure devops 分配环境变量。
First, I tried creating a bash task that would run the command export M2_HOME=/opt/maven
but it didn't work.首先,我尝试创建一个 bash 任务,该任务将运行命令
export M2_HOME=/opt/maven
但它不起作用。
Then i tried azure own instructions: echo "##vso[task.setvariable variable=M2_HOME]/opt/maven"
and it worked fine.然后我尝试了 azure 自己的指令:
echo "##vso[task.setvariable variable=M2_HOME]/opt/maven"
并且效果很好。
The concrete solution was to create two tasks before the maven tasks that assigned all the necessary environment variables, as follows:具体解决方案是在分配所有必要环境变量的 maven 任务之前创建两个任务,如下所示:
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.
如果要定义一个变量并在同一任务中使用它,它将不起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.