We were trying to implement Static Code Analyzers in our Hudson CI and was trying as mentioned here but, i came across about using SONAR for the same feature. We performed the following steps , but got error when the Hudson Job runs
- Installed Sonar & running
- Installed Sonar plugin in Hudson and configured hudson with sonar instance details
- Configured Sonar details for the already defined job
The hudson job ran successfully until it deployed the WAR file to Tomcat6, but it failed when it started the sonar operations.
We received the following error in the Hudson job console
java.io.IOException: Cannot run program "mvn.bat" (in directory "D:\Users\abcd.hudson\jobs\QA Build Local\workspace\view"): CreateProcess error=2, The system cannot find the file specified
mvn.bat -f "D:\Users\abcd\.hudson\jobs\QA Build Local\workspace\view\msaccess\MyApp\Code\appone\pom.xml" -e -B sonar:sonar -Dsonar.host.url=http://localhost:9000/ -Dsonar.language=java FATAL: command execution failed java.io.IOException: Cannot run program "mvn.bat" (in directory "D:\Users\abcd\.hudson\jobs\QA Build Local\workspace\view"): CreateProcess error=2, The system cannot find the file specified at java.lang.ProcessBuilder.start(ProcessBuilder.java:459) at hudson.Proc$LocalProc.(Proc.java:192) at hudson.Proc$LocalProc.(Proc.java:164) at hudson.Launcher$LocalLauncher.launch(Launcher.java:639) at hudson.Launcher$ProcStarter.start(Launcher.java:274) at hudson.Launcher$ProcStarter.join(Launcher.java:281) at hudson.tasks.Maven.perform(Maven.java:263) at hudson.plugins.sonar.utils.SonarMaven.executeMaven(SonarMaven.java:138) at hudson.plugins.sonar.SonarPublisher.executeSonar(SonarPublisher.java:300) at hudson.plugins.sonar.SonarPublisher.perform(SonarPublisher.java:261) at hudson.tasks.BuildStepMonitor$3.perform(BuildStepMonitor.java:36) at hudson.model.AbstractBuild$AbstractRunner.perform(AbstractBuild.java:630) at hudson.model.AbstractBuild$AbstractRunner.performAllBuildSteps(AbstractBuild.java:608) at hudson.model.AbstractBuild$AbstractRunner.performAllBuildSteps(AbstractBuild.java:584) at hudson.model.Build$RunnerImpl.post2(Build.java:159) at hudson.model.AbstractBuild$AbstractRunner.post(AbstractBuild.java:553) at hudson.model.Run.run(Run.java:1390) at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46) at hudson.model.ResourceController.execute(ResourceController.java:88) at hudson.model.Executor.run(Executor.java:145) Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified at java.lang.ProcessImpl.create(Native Method) at java.lang.ProcessImpl.(ProcessImpl.java:81) at java.lang.ProcessImpl.start(ProcessImpl.java:30) at java.lang.ProcessBuilder.start(ProcessBuilder.java:452) ... 19 more Sonar analysis completed: FAILURE
We manually ran the maven-sonar command from command prompt and the sonar analysis completed successfully and the results published in the sonar website.
Note: We observed that the M2_HOME environment variable is not set in the server. Would this be an error ?
Update on Fix:
We set maven_home\bin folder in windows PATH environment variable and then sonar was able to recognize mvn.bat and run.