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
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%
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
Related
I have set M2_HOME under Manage Jenkins -> configure system -> Environment variables and also under Manage Jenkins -> global tool configuration.
When I use maven project, it is working fine.
But when I use freestyle project and execute shell, it throws an error "mvn not found".
But when I give echo $M2_HOME in Execute shell, it shows the correct path.
Also, when I tried $M2_HOME/mvn compile, it worked fine.
I could not figure out the exact issue.
Error
[Compile]
$ /bin/sh -xe /tmp/jenkins1984982949384007169.sh
+ mvn --version
/tmp/jenkins1984982949384007169.sh: 2: /tmp/jenkins1984982949384007169.sh: mvn: not found
Build step 'Execute shell' marked build as failure
Finished: FAILURE
The shell which executes the mvn command doesn't know that the path for the script in in the M2_HOME variable. The shell will only look at commands listed in the $PATH variable.
So there are two solutions:
Always use "$M2_HOME/mvn" to execute Maven (or rather "$M2_HOME/bin/mvn" since M2_HOME should point to the folder which contains bin and lib and not to the script itself).
Change the path at the top of the script to make the shell search in the right place:
export PATH="$M2_HOME/bin:$PATH"
That probably only makes sense when you run Maven more than once in the script.
I have TFS 2012 R2 server as TFS build machine. I a using TFS 2015.2 version. I need to use maven command. I have set path for maven and Java and also updated it in path variable also. I am able to execute maven command in powershell in the server (build machine).
But when I try to execute the same in TFS build definition using powershell inline plugin, it throws me error that mvn is not a recognized command. And when I enter the full path of maven, then it does not fetch me any output.
When I give:
mvn -version
I get following error:
The term 'mvn' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
When I give:
C:\apache-maven-3.3.9\bin\mvn -version
It gives no output
I am not sure, what am I doing wrong. It works well when I execute this directly in server but fails in TFS.
I realised the missing part in it. This is running in poweshell in windows server. In "C:\apacahe-maven-3.3.9\bin" path, there are two "mnv" files. One is mvn.cmd and other is mvn. I was using mvn all this time and it wasn't giving any response. When I use "mvn.cmd", its working fine now.
I build a continuous integration system with Hudson+Maven+ SVN,When I build a job I get this error
While I use maven by command line, it succeed. the configuration of Hudson is below
the environment variable is set well
Hudson can't find the maven executables. You should point the MAVEN_HOME environment variable to the C:\YOUR_PATH_TO_MAVEN_DIRECTORY\bin directory and not to the installation directory itself.
I have a jenkins job that checks out code from TFS and executes a test class using testng.xml
I have Maven properly installed in my machine in C:\JenkinsDependencies\apache-maven
It has mvn.bat file in its bin folder.
But when I execute my job, it fails with the following error.
Checking for pre-build
[TFS_LN_Mobile] $ cmd.exe /C '"C:\JenkinsDependencies\apache-maven\bin\mvn.bat test && exit %%ERRORLEVEL%%"'
Error occurred during initialization of VM
java/lang/NoClassDefFoundError: java/lang/Object
Build step 'Invoke top-level Maven targets' marked build as failure
Checking for post-build
Finished: FAILURE
Below is the configuration of my jenkins job:
I manually executed a batch command as follows:
cd "C:\JenkinsRoot\workspace\TFS_LN_Mobile"
mvn test -DsuiteXmlFile=testng.xml
This works fine.
mvn.bat is a batch script. you can try adding trace of it's variables after steps that might produce this error. take a look at this: Is there any way to trace through the execution of a batch file?
This happens for both: maven projects, and freestyle projects, when maven target is envoked, it tries to execute mvn using absolute path.
[MY-Job] $ tools/Maven/Jenkins_Private_Maven/bin/mvn -f cc/pom.xml -Ddeploy_env=xxx.dev.prv -Dbranch=dev -D-Dsmdist.target=/opt/builds -U clean test -DtestGroups=unit,delegate -Do verride:server=xxx.dev.prv
FATAL: command execution failed
java.io.IOException: Cannot run program "tools/Maven/Jenkins_Private_Maven/bin/mvn" (in directory "workspace/MY-Job"): java.io.IOException: error=2, No such file or directory
I can see that mvn is installed at user's home :
/home/jenkins/tools/Maven/Jenkins_Private_Maven/bin/mvn
but it's trying to run it from the workspace:
/home/jenkins/workspace/MY-Job/tools/Maven/Jenkins_Private_Maven/bin/mvn
Add the default maven installation under (Jenkins -> configuration)
Goto the failing job and make sure you choose the default maven installation from dropdown
Run the job. Success!
Are you sure you have set up Maven in Jenkins -> configuration like this
I have hunch you have a accidental **"."** current directory reference somewhere in your maven set up.
This looks like an auto installed Maven by Jenkins. In which case the previous answers are not correct.
It would seem in this occasion that you have not specified a "remote fs root" for your slave in the salve setup - later versions of Jenkins flag not setting this up correctly as an error.
in Jenkins 2.43:
Manage Jenkins -> Global Tool Configuration -> Maven