Unable to execute maven command on jenkins - maven

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?

Related

Multiple maven install commands in Linux

I am running an azure pipeline for a maven project which has windows commands for maven installation, by calling multiple methods i.e.,
call mvn ... clean install
call mvn ... clean package (authentication)
call mvn ... clean package (restapi)
The build environment is linux Hence I am converting all the commands in the batch file to sh commands. For maven installation I initially added a maven installation task by mentioning the path and commands in the task. This failed.
So I am currently changing the windows commands to sh commands. The other commands except for maven installation have been converted using a batch to sh commands reference article.
Could some one guide me to convert the above mentioned installation commands to sh commands?
If the Apache Maven has been installed and added to the system path on the agent machine where your pipeline runs, you can just try directly calling the mvn command in the bash script, like you call it on Windows.
For example:
mvn ... clean install
mvn ... clean package (authentication)
mvn ... clean package (restapi)
Before you execute the bash script in the pipeline, you firstly should try and debug it on your local machine to make sure it can work as expected on the local machine. Then move the bash script to the pipeline on Azure DevOps.
If the bash script runs failed in the pipeline, for us to investigate this issue further, please share us with the complete debug logs of the failed pipeline run. To get the debug logs, you need to set the pipeline variable System.Debug to true, then trigger the pipeline.

zip -urj command fails in jenkins pipeline shell script

I have jenkins job that add the files to existing zip file
Below is the command that I am using:
zip -urj ./$zipFileName ./template/CM/provision/start.sh
This runs sometimes and sometimes it fails
Here is the log i get on failure:
Build step 'Execute shell' marked build as failure

build failure Jenkins+Maven+SVN

Started by user xxx
Building in workspace C:\Users\Vinay.jenkins\workspace\Orbit App Automation
Updating https://polarisdev.svn.cloudforge.com/qaautomation at revision '2017-12-01T11:04:13.362 +0530'
Using sole credentials xxxx/****** in realm ‘https://polarisdev.svn.cloudforge.com:443 CloudForge login’
At revision 5
No changes for https://polarisdev.svn.cloudforge.com/qaautomation since the previous build
[qaautomation] $ cmd.exe /C "D:\apache-maven-3.5.0\bin\mvn.cmd -f pom.xml '"-Dmaven.repo.local=C:\Users\Vinay.jenkins\workspace\Orbit App Automation.repository"' clean install && exit %%ERRORLEVEL%%"
POM file pom.xml specified the -f/--file command-line argument does not exist
Build step 'Invoke top-level Maven targets' marked build as failure
Sending e-mails to: vinaya.mopidi#orbitanalytics.com
Finished: FAILURE
It is working now ,earlier i have given incorrectly Repository URL (svn url) now given up to svn work space
Correct : https://xxxx.svn.xxx.com/qaautomation/xxxAutomation
InCorrect : https://xxxx.svn.xxx.com/qaautomation
Build step 'Invoke top-level Maven targets' marked build as failure because you entered your shell script in maven goals and options input field.
You command seems to be a free style windows command script .
cmd.exe /C "D:\apache-maven-3.5.0\bin\mvn.cmd -f pom.xml '"-Dmaven.repo.local=C:\Users\Vinay.jenkins\workspace\Orbit App Automation.repository"' clean install && exit %%ERRORLEVEL%%
Select the execute windows batch command radio button in the build step.

Maven wrapper in jenkins

I'm trying to test build a maven based project in jenkins.
https://github.com/tonsV2/Lift-Log-Backend
However I get the following error.
[Lift Log Backend] $ /bin/sh -xe /tmp/hudson4180120395829748105.sh
+ ./mvnw clean
Error: Could not find or load main class org.apache.maven.wrapper.MavenWrapperMain
Build step 'Execute shell' marked build as failure
Finished: FAILURE
Any clues?
Seems like you have spaces in your Jenkins job name. Try to rename your job from "Lift Log Backend" to "Lift-Log-Backend"
I had the same issue, after renaming the Jenkins job, the error was gone.

Maven not recognized in Jenkins

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

Resources