3
votes

I am trying to build a Jenkins Pipeline job. I am trying to put sonarqube scanner configurations into Jenkins pipeline job's Groovy script. Sonarqube configurations in Jenkins Pipeline Job Groovy Script

But when I build the above job I get the following error- Error

Also when I refer to Sonarqube documentation for integrating with Jenkins Pipeline job I get no information about setting the sonarqube properties which otherwise we have to set by adding a step - "execute sonarqube scanner"

enter image description here

Could anyone help in knowing how can we set the Sonarqube properties in jenkins pipeline job which otherwise we can specify in Maven or Freestyle Job Types in Jnekins (shown in above snapshot). Thanks.

Now I have changes the Groovy script of Jenkins Pipeline Job configuration- enter image description here

Now I am getting the error -

enter image description here

Could anyone please help me with the above issue.

2

2 Answers

2
votes

The configuration file is, in my case, always in the application repository and then called from the jenkins job as $WORKSPACE/sonar-project.properties

The content of the file is (example):

# Required metadata
sonar.projectKey=<project-key>
sonar.projectName=<project-name>
sonar.projectVersion=<project-version>

# Comma-separated paths to directories with sources (required)
sonar.sources=src
sonar.exclusions=src/vendor/**/*

# Language
sonar.language=php

# Encoding of the source files
sonar.sourceEncoding=UTF-8

sonar.php.coverage.reportPath=src/coverage-clover.xml #change path to location of your test report
sonar.php.tests.reportPath=src/unitreport.xml  #change path to location of your test report

In Jenkins/Global tool configuration you must add a Sonarqube scanner, looks like this:

enter image description here

And in the manage Jenkins/Configure system you must add your Sonarqube server "redacted Sonarqube" configured like this:

Sonarqube config example

In the job itself you have:

def scannerHome = tool 'azure-tools-sonarqube'  #This is the scanner you added

withSonarQubeEnv('redacted Sonarqube') {  #This is the server you added
  sh "${scannerHome}/bin/sonar-scanner"
}
1
votes

The unsupported major.minor version error happens because you are not running with Java 1.8.
Can you double the version of Java is 1.8 on all slaves including the master where Jenkins is running?
sonar-scanner requires Java 1.8 and your JAVA_HOME variable must point to that.