Reputation: 759
I am trying to learn Jenkins and Maven.
So Far what i have done:
M2
and M2_HOME
as env variables .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.
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
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
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
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
Reputation: 61
add path to slave or ur node then go to folder containing pom.xml and excute mvn clean package
Upvotes: 0
Reputation: 9
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.
Upvotes: 0
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
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
.
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
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.
Upvotes: 1
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:. 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:
Upvotes: 8