简体   繁体   English

Azure 管道无法识别自托管代理中的 mvn

[英]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.

相关问题 Azure 用于 Java 项目的 DevOps 管道,带有自托管代理 - Azure DevOps Pipeline for Java Project with self hosted agent Mvn 未被识别为 Windows 上的 Github Actions 上的命令 自托管运行器 - Mvn is not recognized as a command on Github Actions on Windows a self hosted runner 如何让 Azure Pipelines 通过 Gradle 识别 JavaFX 依赖项 - How to get Azure Pipelines to recognize JavaFX dependency with Gradle 得到差异。 Azure托管代理上的chrome驱动程序错误 - Getting diff. error for chrome driver on azure hosted agent 如何在 Azure 管道 Microsoft 托管代理上升级 java 版本? - How to upgrade java version on an Azure pipeline Microsoft-hosted agent? mvn无法识别正确的Java - mvn wont recognize proper java Azure 管道中的 Java 变量 - Java variables in Azure Pipelines 自注java代理 - Self-injecting java agent Azure 自托管集成运行时加载 ORC 文件时数据工厂管道失败:OutOfMemory 异常,堆大小 - Azure Data Factory pipeline fails when Self-Hosted Integration runtime loads ORC file: OutOfMemory Exception, Heap size mvn:perform不会拉出providerImplementations - mvn:perform does not pull the providerImplementations
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM