Getting an error while integrating SonarQube with Jenkins - jenkins

I followed the SonarQube Jenkins integration tutorial from SonarQube official website. I am getting an error after building my project.
[RetailerWebsite_releaseTestCodeDx] $ "C:\Program Files (x86)\Jenkins2\tools\hudson.plugins.sonar.SonarRunnerInstallation\My_scanner\bin\sonar-scanner.bat" "SonarQube Scanner" -e -Dsonar.host.url=http://10.252.80.55:9000 -Dsonar.projectName=RetailerWebsite -Dsonar.projectVersion=1.0 -Dsonar.projectKey=Retailer-Website -Dsonar.sources=. -Dsonar.projectBaseDir=D:\Builds\RetailerWebsite_releaseTestCodeDx
\Jenkins2\tools\hudson.plugins.sonar.SonarRunnerInstallation\My_scanner\bin\..\jre was unexpected at this time.
ERROR: SonarQube scanner exited with non-zero code: 255
Project Configuration
Global Configuration

It appears you are victim of this Jenkins bug: when using a JRE installed at a path that includes parentheses, Jenkins (on Windows) tries to execute an invalid command.
Workaround: install the JDK elsewhere, and use that one in your Job configuration (or Jenkins itself).

Related

Why Jenkins failure with Error : Exit 9009

I am trying to deploy a Katalon Testcase to Jenkins but some errors appear, such as:
is not recognized as an internal or external command
Exit 9009
Jenkin using old update jenkin.war
You should Update file at : https://jenkins.io/doc/book/installing/#installing-docker
WAR file
The Web application ARchive (WAR) file version of Jenkins can be installed on any operating system or platform that supports Java.
To download and run the WAR file version of Jenkins:
Download the latest stable Jenkins WAR file to an appropriate directory on your machine.
Open up a terminal/command prompt window to the download directory.
Run the command java -jar jenkins.war.
Browse to http://localhost:8080 and wait until the Unlock Jenkins page appears.
Continue on with the Post-installation setup wizard below.
Solve it well

sonar-scanner-2.9.0.670 throws java.lang.ExceptionInInitializerError inside docker container

In this build inside docker (on travis-ci), sonar-scanner-2.9.0.670 throws a java.lang.ExceptionInInitializerError:
ERROR: Error during SonarQube Scanner execution
java.lang.ExceptionInInitializerError
at net.sf.cglib.core.KeyFactory$Generator.generateClass(KeyFactory.java:166)enter code here
Build log here (see line 4660):
https://travis-ci.org/laristra/flecsi/jobs/213157927#L4660
Sonarqube got put into a ubuntu:latest container here:
https://github.com/laristra/flecsi-buildenv/blob/sonarqube/ubuntu#L14
You are working on a C++ project: https://github.com/laristra/flecsi.
You are building it with Travis-CI.
You want to analyze it on SonarQube.com.
You don't need to download any SonarQube Scanner nor set up any SonarQube inside a Docker.
Please:
follow the Get Started guide
, and look at the sample C/C++ project to understand how to trigger a SonarQube analysis using our Travis Addon
It automatically downloads and installs the SonarQube Scanner
It automatically downloads and installs the C/C++ Build Wrapper
It automatically configure everything to point to SonarQube.com
It turned out the problem was Oracle's JDK using openjdk-8-jdk fixed the issue (inside docker).

Jenkins MSBuild SonarQube Runner 1.0.2 projectinfo.xml file not found

I'm having trouble running the sonarqube msbuild runner v1.0.2 in jenkins.
The build runs fine, but the plugin doesn't seem to import the sonar targets correctly.
Here's the logs when the sonar build kicks off:
[workspace] $C:\.jenkins\tools\hudson.plugins.sonar.MsBuildSQRunnerInstallation\MS_Build_Runner_1.0.2\MSBuild.SonarQube.Runner.exe begin /k:my.project /n:myprojectname /v:1.0 /d:sonar.host.url=http://1.1.1.1:9000/
MSBuild SonarQube Runner Bootstrapper 1.0.2.0
Default properties file was found at C:\.jenkins\tools\hudson.plugins.sonar.MsBuildSQRunnerInstallation\MS_Build_Runner_1.0.2\SonarQube.Analysis.xml
Loading analysis properties from C:\.jenkins\tools\hudson.plugins.sonar.MsBuildSQRunnerInstallation\MS_Build_Runner_1.0.2\SonarQube.Analysis.xml
Pre-processing started.
Preparing working directories...
Checking for updates...
MSBuild SonarQube Runner Pre-processor 1.0.2.0
10:17:18.025 Loading analysis properties from C:\.jenkins\tools\hudson.plugins.sonar.MsBuildSQRunnerInstallation\MS_Build_Runner_1.0.2\SonarQube.Analysis.xml
10:17:18.056 Updating build integration targets...
10:17:18.072 Fetching analysis configuration settings...
10:17:21.332 Generating rulesets...
Pre-processing succeeded.
Path To MSBuild.exe: C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe
Executing the command cmd.exe /C " C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe /p:Configuration=Development /t:Clean,Build /tv:14.0 /p:VisualStudioVersion=14.0 /m:1 /fl2 /flp2:verbosity=diagnostic myprojectname.sln " && exit %%ERRORLEVEL%% from C:\.jenkins\jobs\Technology - WWW - Content Store Client\workspace
[workspace] $ cmd.exe /C " C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe /p:Configuration=Development /t:Clean,Build /tv:14.0 /p:VisualStudioVersion=14.0 /m:1 /fl2 /flp2:verbosity=diagnostic ContentStoreClientSolution.sln " && exit %%ERRORLEVEL%%
Microsoft (R) Build Engine version 4.6.81.0...
And here when if finishes:
[workspace] $ C:\.jenkins\tools\hudson.plugins.sonar.MsBuildSQRunnerInstallation\MS_Build_Runner_1.0.2\MSBuild.SonarQube.Runner.exe end
MSBuild SonarQube Runner Bootstrapper 1.0.2.0
Default properties file was found at C:\.jenkins\tools\hudson.plugins.sonar.MsBuildSQRunnerInstallation\MS_Build_Runner_1.0.2\SonarQube.Analysis.xml
Loading analysis properties from C:\.jenkins\tools\hudson.plugins.sonar.MsBuildSQRunnerInstallation\MS_Build_Runner_1.0.2\SonarQube.Analysis.xml
Post-processing started.
No ProjectInfo.xml files were found. Possible causes: you specified an invalid build configuration or the custom MSBuild analysis targets were not imported.
MSBuild SonarQube Runner Post-processor 1.0.2.0
Generation of the sonar-properties file failed. Unable to complete SonarQube analysis.
10:21:04.257 Creating a summary markdown file...
Post-processing failed. Exit code: 1
ERROR: Execution of MSBuild SonarQube Runner failed (exit code 1)
The plugin installs itself int he tools subfolder of jenkins. But, looking in the project workspace, I can see a folder called .sonar that appears to have all the correct files and targets etc in it.
Any ideas on why the build is failing?
You need to use MSBuild 12 at least (version 14, shipping with VS 2015 will give you more accurate analysis results with version 1.1 of the SonarQube Scanner for MSBuild & C# Plugin 4.4).
The ImportsBefore targets are not deployed for MSBuild 4.0 - which is why no information is being collected during your MSBuild execution. We're not going to add support for MSBuild 4.0 or earlier versions.
Note that in the upcoming SonarQube Scanner for MSBuild 1.1 version, the error message mentioning ProjectInfo.xml has been largely improved to let you know about the potential root causes: See https://jira.sonarsource.com/browse/SONARMSBRU-180

Cannot run program "gradle" in Jenkins

I've installed the Gradle plugin for Jenkins. When I try to build the project I get the following error:
[workspace] $ gradle clean -b build/build.gradle
FATAL: command execution failed
java.io.IOException: Cannot run program "gradle" (in directory "/Users/Shared/Jenkins/Home/jobs/test/workspace"): error=2, No such file or directory
at java.lang.ProcessBuilder.start(ProcessBuilder.java:460)
at hudson.Proc$LocalProc.<init>(Proc.java:244)
at hudson.Proc$LocalProc.<init>(Proc.java:216)
at hudson.Launcher$LocalLauncher.launch(Launcher.java:707)
at hudson.Launcher$ProcStarter.start(Launcher.java:338)
at hudson.Launcher$ProcStarter.join(Launcher.java:345)
at hudson.plugins.gradle.Gradle.performTask(Gradle.java:201)
at hudson.plugins.gradle.Gradle.perform(Gradle.java:97)
at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:19)
at hudson.model.AbstractBuild$AbstractRunner.perform(AbstractBuild.java:695)
at hudson.model.Build$RunnerImpl.build(Build.java:178)
at hudson.model.Build$RunnerImpl.doRun(Build.java:139)
at hudson.model.AbstractBuild$AbstractRunner.run(AbstractBuild.java:465)
at hudson.model.Run.run(Run.java:1404)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46)
at hudson.model.ResourceController.execute(ResourceController.java:88)
at hudson.model.Executor.run(Executor.java:238)
Caused by: java.io.IOException: error=2, No such file or directory
at java.lang.UNIXProcess.forkAndExec(Native Method)
at java.lang.UNIXProcess.<init>(UNIXProcess.java:53)
at java.lang.ProcessImpl.start(ProcessImpl.java:91)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:453)
... 16 more
Build step 'Invoke Gradle script' changed build result to FAILURE
Build step 'Invoke Gradle script' marked build as failure
Finished: FAILURE
Running the task $ gradle clean -b build/build.gradle from the command line works as expected.
I had the same issue and found that the problem for me was the gradle version in the project configuration. It was set to Default and when I set it to the gradle version I was pointing to in the plugin configuration in the Manage Jenkins > Configuration Options, It found gradle and worked properly.
This is a difficult issue to debug and I hope this saves someone else some time.
Solution Mastering_the_Object pointed out worked form me too, just to clarify steps there:
just installing Gradle plugin in Jenkins is not enough, you must also go to:
Jenkins->Manage Jenkins->Configure Jenkins->Configure system.
Under "Gradle Installations" type in name (it appears as version in project configuration), check "Install automatically" and select version. Then you can select that "Gradle version" in project configuration.
I was getting this error using the Gradle wrapper, was able to fix my broken build as follows:
Go to Manage Jenkins -> Global Tool Configuration -> Gradle -> Add Gradle, give it a name
Go to Jenkins -> (your job) -> Configure -> Build, choose "Invoke Gradle" and change the Gradle version from (Default) to the named version
When running Gradle on a CI machine such as Jenkins, it's most convenient to use the Gradle Wrapper.
On your development machine, stand in your root project directory and run
gradle wrapper
Then, check in the resulting files into your source control system. After that, you don't have to install anything on your Jenkins server if you need to change Gradle versions. Just configure your Jenkins job like this:
Quoting from the Gradle User Guide:
By distributing the wrapper with your project, anyone can work with it
without needing to install Gradle beforehand. Even better, users of
the build are guaranteed to use the version of Gradle that the build
was designed to work with. Of course, this is also great for
continuous integration servers (i.e. servers that regularly build your
project) as it requires no configuration on the server.
The jenkins can not find the gradle executable. I have never made gradle wrapper to work. Please follow the following steps:
Download gradle ( http://gradle.org/downloads),
unpack it to, e.g., /usr/local/lib/gradle ,
open /etc/profile and add the following two lines:
export GRADLE_HOME=/usr/local/lib/gradle
export PATH=$PATH:$GRADLE_HOME/bin
It works for my jenkins installation.
ps. I answer this old question, because it is a common issue when setting up gradle with jenkins. I have spent some time trying to make the gradle wrapper work without success before.
Used both #Skarab & a number of other solutions here to get it to work.
Download gradle ( http://gradle.org/downloads),
unpack it to, e.g., /usr/local/lib/gradle ,
open /etc/profile and add the following two lines:
export GRADLE_HOME=/usr/local/lib/gradle
export PATH=$PATH:$GRADLE_HOME/bin
Then under Manage Jenkins > Configure system > Gradle, defined GRADLE_HOME and gave that gradle installation a name
Then, {this could be a bug} for the project, change gradle version from Default to the one I defined above
As others have noted, this is because Jenkins can't find the gradle executable.
None of the published solutions worked for me, but I was able to fix the problem by adding the gradle bin dir to the path set in the .bashrc for the build account on the build slave. Modifying the .profile failed, and setting PATH in the jenkins node configuration also failed.
Some posts will suggest setting the gradle path in the tools menu, but no gradle entry was available there either (perhaps due to regressions / design changes in the gradle plugin?).
In any case, the best test I found (short of running the build again and watching for failure) was to run env over ssh:
ssh <host> env
and check the PATH variable defined that way; if gradle isn't in that path, you probably won't be able to run it from jenkins.

Sonar plugin not working for projects that use ANT as a build script

Problem
I have just installed the Sonar Jenkins plugin. I went into my configured job (a free style job) that produces a WAR file artifact through an ANT build and did as follows:
Check the Sonar checkbox. (No problems here)
Configure the install dir of sonar (No problems here)
Checked the checkbox that states: "Check if this project is NOT built with maven 2" (I am confused here)
I have checked that box because I am not using maven for build, I am using ANT but it still asked me for required properties that resemble a lot MVN such as: Organization id, project id, project name, project version, source directories... etc..
So I have filled those as well. When I click the play button "Build Now" the build seems to be running fine as it always had prior to sonar installation but it fails at the very end because its trying to execute MAVEN.
See as follows:
$ mvn -f /root/.jenkins/jobs/HRDA/workspace/pom.xml -e -B sonar:sonar
FATAL: command execution failed
java.io.IOException: Cannot run program "mvn" (in directory "/root/.jenkins/jobs/HRDA/workspace"): java.io.IOException: error=2, No such file or directory
Questions
Why is Sonar trying to execute Maven if I have checked the box that said check this box if you do NOT use Maven 2?
Can I make use of this Sonar plugin if my apps are built with ANT, GANT, GRADLE?
Do I have to reconvert my apps to use MVN builds?
Thanks,
- Dario
Like Oers suggested on my question comments if you are using ANT as a build script in your CI server (Jenkins in my case) you will have to use the SONAR-ANT-TASK to generate Sonar reports, do as follows:
Download MySQL or any other Sonar supported RDBMS such as Postgres, Oracle, etc..'
Download and Install sonar server.
go to (sonar installation folder)/extras/database/mysql and run the create_database.sql script.
I had to run an extra sql statement in my case using mysql, you can see here Unable to access Sonar MySQL database Caused by: java.sql.SQLException: Access denied for user 'sonar'#'glassfishdev.ccs.local' (using password: YES)
Start Sonar by typing ./sonar.sh start
Add the sonar ant task to your build script. You can follow this template http://docs.codehaus.org/display/SONAR/Analyse+with+Ant+Task+1.0
DO NOT check the sonar check box in your Configure screen if you have the Hudson Sonar plugin for installed, as this plugin only works with Maven projects.
Click the "Build Now" button. If everything above has been done correctly you should be able to see the reports at http://ipaddressofmachinesonarisinstalled:9000/
Hope this helps,
-Dario

Resources