Jack Shepherd
Jack Shepherd

Reputation: 393

Jenkins - 'mvn' is not recognized as an internal or external command, operable program or batch file

I have jenkins installed with the maven plugin.

I have maven installed on the same jenkins machine, and I'm able to run 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"

However, when I trigger a maven build, I'm getting this error

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

Upvotes: 1

Views: 6937

Answers (2)

Yiannis Dermitzakis
Yiannis Dermitzakis

Reputation: 488

On the Jenkins server, you need to go to Manage Jenkins > Global Tool Configuration and find "Maven installations". There you can set it up.

Also, you should avoid directly calling Maven via the command-line in your jobs. Try a "Maven Project" or a "Free-Style Project" (then using a Build step of "Invoke top-level Maven targets").

Upvotes: 1

sozkul
sozkul

Reputation: 675

Maybe it is about quoting. Try this;

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

Also check this

Upvotes: 0

Related Questions