7

I have installed Tomcat 7 on Windows 8, on which Jenkins is deployed. I configured the JDK, Ant and Maven in the Jenkin settings. In the Maven section, I gave a name as LocalMaven and the MAVEN_HOME as C:\Techie\apache-maven. When I did a test build, it gave me the following error that the mvn.bat is not recognized. Then I checked by entering mvn command in CMD. It gave some maven statements, which means maven is available in the PATH variables.

After googling, I changed the MAVEN_HOME as **%M2_HOME%\bin** in Jenkin-Maven configuration. Still it did not work.

LOG:

  • [workspace] $ cmd.exe /C '"mvn.bat -f HighScoresServiceClient compile && exit %%ERRORLEVEL%%"'

  • 'mvn.bat' 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

Edited: Added the analysis

The command executed by Jenkins is [workspace] $ cmd.exe /C '"mvn.bat -f String-replacer compile && exit %%ERRORLEVEL%%"' where mvn.bat is not a valid command and so Jenkins errors out as follows that 'mvn.bat' is not recognized as an internal or external command, I think Jenkins should call the command as mvn and not mvn.bat. Can some experts correct me if I am wrong? Please let me know how to change this behaviour if I am right.

Edited: Attached the Configuration Maven-JDK-Git Configuration in Jenkins

Maven is available in the PATH variables

Anand
  • 727
  • 3
  • 14
  • 39

2 Answers2

5

I suppose your Tomcat server is running as a Windows service.

Did you create your MAVEN_HOME and M2_HOME as system environment variables? (idem for your PATH)

Another solution is to configure your variables in the apache-tomcat/bin/setenv.bat file:

set MAVEN_HOME=C:\Techie\apache-maven
set PATH=%MAVEN_HOME%\bin;%PATH%
11thdimension
  • 10,333
  • 4
  • 33
  • 71
Bruno Lavit
  • 10,184
  • 2
  • 32
  • 38
  • I tried creating the system variables. It did not work. I even added the contents into setenv.bat file. It did not help :( – Anand May 21 '15 at 07:43
  • When you configured Maven in your Jenkins settings, you declared the installation in the Maven section? Did you try the "install automatically" option? – Bruno Lavit May 21 '15 at 07:51
  • A last test, on your job, can you try to use the Inject Env plugin and force the PATH to %PATH%;C:\Techie\apache-maven\bin? Just to check if this solved your pb. – Bruno Lavit May 21 '15 at 08:10
  • This time, I get a different error. Path is displayed. ----ERROR LOG--- [EnvInject] - Executing and processing the following script content: %PATH%;C:\Techie\apache-maven\bin [workspace] $ cmd /c call c:\Techie\servers\apache-tomcat-7.0.61\temp\hudson2494005029985865936.bat 'C:\Apps\Java\jdk1.7.0_67/bin' is not recognized as an internal or external command, operable program or batch file. C:\Users\Anand\.jenkins\jobs\test-build-3\workspace>exit 9009 [EnvInject] - Script executed. The exit code is 9009. [EnvInject] - Fail the build. Finished: FAILURE – Anand May 21 '15 at 08:31
  • Can you post some screen copies to show us how you declared your Maven/Java/Ant stuff with Jenkins? – Bruno Lavit May 21 '15 at 08:42
  • 5
    Your settings seem OK. On your Jenkins job, did you choose your "LocalMaven" in the Maven version listbox? – Bruno Lavit May 22 '15 at 10:09
  • 1
    Thanks for your comments, which really helped. It was having the default value and once I changed it to LocalMaven, it worked fine. Thanks a lot Bruno... – Anand May 25 '15 at 00:27
  • @BrunoLavit Thank you bruno :) – Mohammed shebin Nov 12 '15 at 10:49
5

I bet you've installed Maven 3.3 that has mvn.bat renamed to mvn.cmd

There is a report on this issue in Jenkins JIRA: https://issues.jenkins-ci.org/browse/JENKINS-27525

  • 1
    This issue is resolved and available by upgrading Jenkins. To get it to work I upgraded Jenkins itself and the Maven Integration plugin. To get it to work I ALSO had to explicitly specify the new Maven version in the project configuration, even though it was configured to use the "default" Maven version which I updated to point to the new 3.3 one. – Henno Vermeulen Aug 10 '15 at 10:35