2
votes

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

  1. Installed Sonar & running
  2. Installed Sonar plugin in Hudson and configured hudson with sonar instance details
  3. Configured Sonar details for the already defined job
  4. 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.

3
Looks like Maven is not correctly configured. Not a Sonar issueMark O'Connor
@Mark O'Connor our observation on the M2_HOME made us also suspect on the same lines. But what could be that Maven configuration that has gone wrong and failing. The same maven is perfectly running when the SONAR was disabled. I want to share the screenshot of these settings.. how to share them in StackOverFlow ? (any community guidelines to follow ?)yathirigan
picturepush.com/public/8830923 - SONAR Settings in Job picturepush.com/public/8831001 - Maven Settings for the Jobyathirigan

3 Answers

2
votes

Sonar is being run as a separate Maven program. The command line is being displayed at the top of the log:

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

This is expected, you attached screen shots specified this Sonar configuration.

Your problem does not appear to be the job configuration, instead Jenkins is unable to find the "mvn.bat" command....

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

You need to investigate how you've configured Maven.

1
votes

I had the same. In my case I had to change location of maven directory - when it was in "c:\Program Files (x86)\wamp\bin\apache-maven-3.2.1\" it couldn't run, but when I moved it to "c:\maven" (and changed system variable: "Path" including "C:\maven\bin" and created by me "MAVEN_HOME = c:\maven"). I had to reboot computer to work - check in windows console (logo windows -> run "cmd") by typing "mvn -version" and you should have line "Maven home: C:\maven"

0
votes

Installation

  • Jenkins installed as war in Tomcat
  • Tomcat installed as a service in Windows

I've installed Maven and correctly configured environment variables in Windows

Problem

FATAL: command execution failed
java.io.IOException: Cannot run program "mvn.bat" (in directory "C:\.jenkins\workspace\my_project"): CreateProcess error=2, The system cannot find the file specified
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:470)
    at hudson.Proc$LocalProc.<init>(Proc.java:244)
    at hudson.Proc$LocalProc.<init>(Proc.java:216)
    at hudson.Launcher$LocalLauncher.launch(Launcher.java:803)
    at hudson.Launcher$ProcStarter.start(Launcher.java:381)
    at hudson.Launcher$ProcStarter.join(Launcher.java:388)
    at hudson.tasks.Maven.perform(Maven.java:328)
    at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
    at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:770)
    at hudson.model.Build$BuildExecution.build(Build.java:199)
    at hudson.model.Build$BuildExecution.doRun(Build.java:160)
    at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:533)
    at hudson.model.Run.execute(Run.java:1759)
    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
    at hudson.model.ResourceController.execute(ResourceController.java:89)
    at hudson.model.Executor.run(Executor.java:240)
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.<init>(ProcessImpl.java:177)
    at java.lang.ProcessImpl.start(ProcessImpl.java:28)
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:452)

Solution

I've restarted Tomcat service so it has loaded the last configured Maven's environment variables making them available to Jenkins.