sonar qube on jenkins pipeline - maven

How can I make that sonnar qube server analyze a mvn project on jenkins?. I have a pipeline project from CSM with a jenkinfile which point to a groovy file where all steps of the job are executed. All steps are working ok (mvn test, mvn package, mvn compile, etc), but donĀ“t know how to execute the mvn sonar:sonar. It gives following error.Image show how do I have sonar configured in jenkins and the job step where it fails.
And this is how I have the step described in groovy file of pipeline:
stage ('SonarQube analysis') {
withSonarQubeEnv('https://sonarqube.xxxxx.com') {
sh 'mvn sonar:sonar'
}
}

Try using the server installation name in withSonarQubeEnv, right now you are using URL i.e. withSonarQubeEnv('Grey Azure Sonarqube').
Documentation

Related

Jenkins Karate pipeline project could not execute maven goal

Error message from the Jenkins console:
The goal you specified requires a project to execute but there is no
POM in this directory
(/home/jenkins/workspace/Dealer-API-v2-test-automation_qa). Please
verify you invoked Maven from the correct directory.
Maven command in the Jenkins file:
sh script : "mvn test '-Dkarate.options=--tags #regression' -Dtest=TestParallel -DargLine='-Dkarate.env=qa'"
How can I execute this maven command in my pipeline script?
Just a guess but if you add -f Dealer-API-v2-test-automation_qa/pom.xml or something like that, it may start working. Or do a cd Dealer-API-v2-test-automation_qa, before doing mvn test, hope that helps.

SonarQube analysis from maven and Jenkins have different results

I am using SonarQube version 6.7 for running analysis of Maven projects using the command mvn clean verify sonar:sonar from the project directory using command prompt and get the results. The sonar configurations in settings.xml for maven (v3.5.3) are added respectively.
In Jenkins (version 2.161), I have installed SonarQube Scanner for Jenkins (v2.8.1) plugin. The SonarQube Server configuration is configured as below.
In the Jenkins maven project, I have configured the post steps as below.
I have checked the Prepare SonarQube Scanner environment in the Build Environment section and the Build goal is -e clean verify sonar:sonar.
My issue is, when the SonarQube analysis for a maven project is triggered through command prompt using the command mvn clean verify sonar:sonar, I am getting the results as expected. But when the Jenkins job is triggered with the configurations above for the same maven project, the results are different and incorrect. What am I missing?
P.S- In the Post-build Actions, I can see the SonarQube analysis with maven is deprecated.
Thanks in advance.
You use different scanners. First you used SonarScanner for Maven (mvn sonar:sonar). Next you used Basi SonarScanner, which requires manual configuration of all options.
The best option to sole it is always use the same scanner. You have Maven project, so you can enable Prepare SonarQube Scanner environment in Build Environment, and next execute Sonar goal $SONAR_MAVEN_GOAL in Build.

Failure at Maven clean deploy

In my Jenkins pipeline I try to build in the Maven Surefire Plugin so I can run Maven Test within the Pipeline and ignore the failure of the Test (so that the pipeline process can go on):
mvn clean deploy -Dmaven.test.failure.ignore=false
However if I try to use the command I get following error:
class org.codehaus.groovy.ast.expr.UnaryMinusExpression, with its value 'Dmaven.test.failure.ignore', is a bad expression as the left hand side of an assignment operator at line: 6 column: 51. File: WorkflowScript # line 6, column 51.
oy -Dmaven.test.failure.ignore=false
^
I don't quite understand why it won't work, can anyone explain?
Your command line call of Maven is interpreted as groovy command. This means that you made a syntax error in your groovy script.
Yo need to use the pipeline maven plugin and run the maven call with a shell step:
https://wiki.jenkins.io/display/JENKINS/Pipeline+Maven+Plugin
Example:
withMaven(
// Maven installation declared in the Jenkins "Global Tool Configuration"
maven: 'M3',
// Maven settings.xml file defined with the Jenkins Config File Provider Plugin
// Maven settings and global settings can also be defined in Jenkins Global Tools Configuration
mavenSettingsConfig: 'my-maven-settings',
mavenLocalRepo: '.repository') {
// Run the maven build
sh "mvn clean deploy -Dmaven.test.failure.ignore=false"
} // withMaven will discover the generated Maven artifacts, JUnit Surefire & FailSafe reports and FindBugs reports

Build Jenkins Sonar-ruby-plugin

I am trying to build sonar-ruby-plugin for jenkins i.e, to create a .hpi file every time I run the command:
mvn package
it creates a target folder but there is no .hpi file.
https://github.com/GoDaddy-Hosting/ruby-sonar-plugin
This is a plugin for SonarQube server, not Jenkins.
You should:
build the plugin by mvn package
copy to SONARQUBE_HOME/extensions/plugins directory
restart SonarQube
run analysis (you can execute SonarQube in Jenkins; read more on SonarQube wiki)

running maven sonar from unix

I have a mvn project. I want to run it against sonar.
e.g. the following command - mvn org.codehaus.mojo:sonar-maven-plugin:2.0:sonar
Without going in and modifying the application pom file to add sonar plugin, is there another way that I can call the mvn command and reference sonar plugin ?
I don't know how it works, but if you execute it from Jenkins with the Sonar plugin it will work without modifying your pom.xml.

Resources