詹金斯 - ' mvn'不被识别为内部或外部命令,可操作程序或批处理文件

时间:2016-07-19 06:01:45

标签: java maven jenkins maven-3

我已经使用maven插件安装了jenkins。

我在同一个jenkins机器上安装了maven,我能够运行mvn -version

C:\Users\admin>mvn -version
Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-11T00:41:4
7+08:00)
Maven home: C:\maven\apache-maven-3.3.9\bin\..
Java version: 1.8.0_91, vendor: Oracle Corporation
Java home: C:\Program Files\Java\jdk1.8.0_91\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows server 2012 r2", version: "6.3", arch: "amd64", family: "dos"

但是,当我触发maven构建时,我收到此错误

Checking out Revision 04eca9e1337cc307bf435d182e52c82469f27f33 (refs/remotes/origin/master)
 > git.exe config core.sparsecheckout # timeout=10
 > git.exe checkout -f 04eca9e1337cc307bf435d182e52c82469f27f33 
 > git.exe rev-list 04eca9e1337cc307bf435d182e52c82469f27f33  # timeout=10
[workspace] $ cmd.exe /C "mvn -f pom.xml && exit %%ERRORLEVEL%%"
'mvn' is not recognized as an internal or external command,
operable program or batch file.
Build step 'Invoke top-level Maven targets' marked build as failure
Finished: FAILURE

2 个答案:

答案 0 :(得分:1)

在Jenkins服务器上,您需要转到Manage Jenkins>全局工具配置和查找" Maven安装"。在那里你可以设置它。

此外,您应该避免在作业中通过命令行直接调用Maven。试试" Maven项目"或者#34;自由式项目" (然后使用&#34的构建步骤;调用顶级Maven目标")。

答案 1 :(得分:0)

也许是关于引用。试试这个;

cmd.exe /k ""C:\maven\apache-maven-3.3.9\bin\mvn.exe" -f pom.xml & "exit %%ERRORLEVEL%%""

同时检查this