user2048204
user2048204

Reputation: 759

Maven and Jenkins - 'mvn' is not recognized as an internal or external command,

I am trying to learn Jenkins and Maven.

So Far what i have done:

  1. Installed Maven and set M2 and M2_HOME as env variables
  2. Created a simple maven project from eclipse. --> Created a .bat file in which I am moving to the directory where the pom.xml file is located and running mvn clean package. I run this bat file.

Everything went as expected till here.

  1. Now I installed jenkins and created a item (or job) > Added build step as "Execute Windows batch command" . and entered the bat location.

But I am getting the following error:

*Started by user anonymous*
*Building in workspace C:\Users\abhi\ .jenkins\jobs\Maven\workspace*
*[workspace] $ cmd /c call C:\WINDOWS\TEMP\hudson6018913903543004539.bat*

*C:\Users\abhi\ .jenkins\jobs\Maven\workspace>C:\Users\abhi\Desktop\ma.bat*

*C:\Users\abhi\ .jenkins\jobs\Maven\workspace>E:*

*E:\>cd AllStuffLearning\EclipseWorkSpaces\MavenWorkSpace\MyMavenPrj\ *

*E:\AllStuffLearning\EclipseWorkSpaces\MavenWorkSpace\MyMavenPrj>chdir*
*E:\AllStuffLearning\EclipseWorkSpaces\MavenWorkSpace\MyMavenPrj*

*E:\AllStuffLearning\EclipseWorkSpaces\MavenWorkSpace\MyMavenPrj>mvn clean* *package *
*'mvn' is not recognized as an internal or external command,*
*operable program or batch file.*
*Build step 'Execute Windows batch command' marked build as failure*
*Finished: FAILURE*

Upvotes: 4

Views: 34118

Answers (9)

Pratik Gaurav
Pratik Gaurav

Reputation: 907

I solved this problem by adding the M2_HOME and path in system variable in Windows earlier it as user level.

Upvotes: 0

nikhil bhardwaj
nikhil bhardwaj

Reputation: 1

the issue is because in Jenkins environment variable to the maven path and M2_home is not set

go to ->Jenkins ->system information->system variables

this path is taken by Jenkins when you install it on your system , i fixed it using reinstalling Jenkins

Upvotes: 0

Sugat Shivsharan
Sugat Shivsharan

Reputation: 595

Go to ->Configure-> Build Under 'Execute Windows Batch Command' please write the below code

set path=C:\Users\<name>\apache-maven-3.6.3-bin\apache-maven-3.6.3\bin
c:
cd C:\Users\<name>\Selenium_SSCApplication\Maven_Selenium_SSCApplication
mvn clean test

Upvotes: -1

Arunima Vasudevan
Arunima Vasudevan

Reputation: 61

add path to slave or ur node then go to folder containing pom.xml and excute mvn clean package

Upvotes: 0

This might be one of root cause, Might be your Jenkins not recognizing your MAVEN path which is saved in windows environment variable. I have came across same issue, to mitigate this MOVE UP MAVEN path in environment variable, please refer screenshot.

enter image description here

Upvotes: 0

Jasser
Jasser

Reputation: 213

Even after setting the path for maven, I was getting the same result. You can directly execute the cmd command as your/path/to/mvn/installation/mvn clean package

Upvotes: 0

mainframer
mainframer

Reputation: 22069

I have met the same error when I tried to run Maven project from Jenkins with an windows slave.Finally I've solved this issue by setting M2_HOME and path environments rights before the command mvn clean test.

enter image description here

Hope this help someone who still get the mvn' is not recognized as an internal or external command error after setting M2_HOME environment and tool location.

Upvotes: 8

OhadR
OhadR

Reputation: 8839

In Jenkins you have "build environment" section (under "Configure", of course). There you have "Properties Content", and there you should add M2 and M2_HOME as well.

enter image description here

Upvotes: 1

khmarbaise
khmarbaise

Reputation: 97399

The appropriate way is to define the location of such tools via the system configuration. Manage Jenkins and System Configuration and there you can do it like this:Maven Installation in Jenkins. Than there is no need to define properties etc. If you do this for different versions for example for Maven..than you can select the different version in your job like this: Maven Installation selection

Upvotes: 8

Related Questions