i'm getting the above error eventhoug it has all the properties. all the sonar properties defined in -Dsettings=./sonar-project.properties file. still getting the same error.
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (sonarqube analysis)
[Pipeline] withSonarQubeEnv Injecting SonarQube environment variables using the configuration: sonar
[Pipeline] {
[Pipeline] sh
+ /var/jenkins_home/tools/hudson.plugins.sonar.SonarRunnerInstallation/sonar/bin/sonar-scanner -
Dproject.settings=./sonar-project.properties
INFO: Scanner configuration file:
/var/jenkins_home/tools/hudson.plugins.sonar.SonarRunnerInstallation/sonar/conf/sonar-
scanner.properties
INFO: Project root configuration file: NONE
INFO: SonarScanner 4.6.2.2472
INFO: Java 1.8.0_292 AdoptOpenJDK (64-bit)
INFO: Linux 3.10.0-1160.24.1.el7.x86_64 amd64
INFO: User cache: /var/jenkins_home/.sonar/cache
INFO: Scanner configuration file:
/var/jenkins_home/tools/hudson.plugins.sonar.SonarRunnerInstallation/sonar/conf/sonar-
scanner.properties
INFO: Project root configuration file: NONE
INFO: Analyzing on SonarQube server 7.5.0
INFO: Default locale: "en_US", source code encoding: "UTF-8" (analysis is platform dependent)
INFO: Publish mode
INFO: Load global settings
INFO: Load global settings (done) | time=122ms
INFO: Server id: BF41A1F2-AXjqWPPbWWxxqvtkaXSc
INFO: User cache: /var/jenkins_home/.sonar/cache
INFO: Load/download plugins
INFO: Load plugins index
INFO: Load plugins index (done) | time=60ms
INFO: Load/download plugins (done) | time=1203ms
INFO: Loaded core extensions:
INFO: Process project properties
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 4.114s
INFO: Final Memory: 11M/219M
INFO: ------------------------------------------------------------------------
ERROR: Error during SonarScanner execution
ERROR: You must define the following mandatory properties for 'Unknown': sonar.projectKey,
sonar.sources
ERROR:
ERROR: Re-run SonarScanner using the -X switch to enable full debug logging.
[Pipeline] }
WARN: Unable to locate 'report-task.txt' in the workspace. Did the 'SonarScanner' succeed?
[Pipeline] // 'withSonarQubeEnv'
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // 'withEnv'
[Pipeline] }
[Pipeline] // 'withEnv'
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code 2
Finished: FAILURE
Shell Script -- ${scannerHome}/bin/sonar-scanner -Dproject.settings=./sonar-project.properties (self time 2s)
/var/jenkins_home/tools/hudson.plugins.sonar.SonarRunnerInstallation/sonar/bin/sonar-scanner -Dproject.settings=./sonar-project.properties
INFO: Scanner configuration file: /var/jenkins_home/tools/hudson.plugins.sonar.SonarRunnerInstallation/sonar/conf/sonar-scanner.properties
INFO: Project root configuration file: NONE
INFO: SonarScanner 4.6.2.2472
INFO: Java 1.8.0_292 AdoptOpenJDK (64-bit)
INFO: Linux 3.10.0-1160.24.1.el7.x86_64 amd64
INFO: User cache: /var/jenkins_home/.sonar/cache
INFO: Scanner configuration file: /var/jenkins_home/tools/hudson.plugins.sonar.SonarRunnerInstallation/sonar/conf/sonar-scanner.properties
INFO: Project root configuration file: NONE
INFO: Analyzing on SonarQube server 8.9.0
INFO: Default locale: "en_US", source code encoding: "UTF-8" (analysis is platform dependent)
WARN: SonarScanner will require Java 11 to run, starting in SonarQube 9.x
INFO: Load global settings
INFO: Load global settings (done) | time=90ms
INFO: Server id: BF41A1F2-AXl0u-SQAyVEzukSwxVv
INFO: User cache: /var/jenkins_home/.sonar/cache
INFO: Load/download plugins
INFO: Load plugins index
INFO: Load plugins index (done) | time=51ms
INFO: Load/download plugins (done) | time=92ms
INFO: Process project properties
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 1.837s
INFO: Final Memory: 9M/125M
INFO: ------------------------------------------------------------------------
ERROR: Error during SonarScanner execution
ERROR: You must define the following mandatory properties for 'Unknown': sonar.projectKey
ERROR:
ERROR: Re-run SonarScanner using the -X switch to enable full debug logging.
Related
im trying to integrate SonarQube with jenkins but im facing some errors
This is my analysis properties
sonar.projectBaseDir=/var/lib/jenkins/workspace/sonarqube
sonar.language=Java
#sonar.login=
sonar.projectVersion=1.0
sonar.sources=.
sonar.verbose=true
sonar.projectKey=sonarqube
sonar.host.url=http://x.xxx.xx.xxx:9000/
sonar.projectName=sonarqube
sonar.sourceEncoding=UTF-8
sonar.project.settings=/var/lib/jenkins/workspace/sonarqube/sonarqube-scanner/sonar-project.properties
sonar.analysis.mode=publish
sonar.buildbreaker.skip=true
It shows me this error msg
08:02:22.935 DEBUG: Extract sonar-scanner-api-batch in temp...
08:02:22.961 DEBUG: Get bootstrap index...
08:02:22.962 DEBUG: Download: http://x.xxx.xx.xxx:9000/batch/index
08:02:27.994 ERROR: SonarQube server [http://x.xxx.xx.xxx:9000/] can not be reached
08:02:27.994 INFO: ------------------------------------------------------------------------
08:02:27.994 INFO: EXECUTION FAILURE
08:02:27.994 INFO: ------------------------------------------------------------------------
08:02:27.995 INFO: Total time: 5.588s
08:02:28.020 INFO: Final Memory: 3M/56M
08:02:28.020 INFO: ------------------------------------------------------------------------
08:02:28.020 ERROR: Error during SonarScanner execution
org.sonarsource.scanner.api.internal.ScannerException: Unable to execute SonarScanner analysis
is there any suggestion for this problem?
How to resolve this " org.sonarqube.ws.client.HttpException: Error 401 " error of sonarqube quality gates.
i'm getting above error during third stage build pipeline in jenkins.
SonarQube-Scanner Version: 4.5.0.2216
SonarQube-Server Version: 8.6.0.39681
Jenkins-Server Version: 2.235.5
Below is my build pipeline
node {
stage('Clone the Git') {
git 'https://github.com/SonarSource/sonar-scanning-examples'
}
stage('SonarQube analysis') {
def scannerHome = tool 'sonarqube';
withSonarQubeEnv('sonarqube-server') {
sh "${scannerHome}/bin/sonar-scanner \
-D sonar.login=admin \
-D sonar.password=admin \
-D sonar.projectKey=sonarqubetest3 \
-D sonar.exclusions=vendor/**,resources/**,**/*.java \
-D sonar.host.url=http://192.168.0.4:9000/"
}
}
stage('Quality Gates'){
timeout(time: 1, unit: 'HOURS') {
def qg = waitForQualityGate()
if (qg.status != 'OK') {
error "Pipeline aborted due to quality gate failure: ${qg.status}"
}
}
}
}
# Below is the complete jenkins job log
Started by user admin
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] Start of Pipeline
[Pipeline] node
Running on Jenkins in /var/jenkins_home/workspace/sonar-qube-testing
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Clone the Git)
[Pipeline] git
The recommended git tool is: NONE
No credentials specified
> git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
> git config remote.origin.url https://github.com/SonarSource/sonar-scanning-examples # timeout=10
Fetching upstream changes from https://github.com/SonarSource/sonar-scanning-examples
> git --version # timeout=10
> git --version # 'git version 2.11.0'
> git fetch --tags --progress -- https://github.com/SonarSource/sonar-scanning-examples +refs/heads/*:refs/remotes/origin/* # timeout=10
> git rev-parse refs/remotes/origin/master^{commit} # timeout=10
> git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10
Checking out Revision 1cbdd40467f475fcdbd8367ca00b65acbf774e3f (refs/remotes/origin/master)
> git config core.sparsecheckout # timeout=10
> git checkout -f 1cbdd40467f475fcdbd8367ca00b65acbf774e3f # timeout=10
> git branch -a -v --no-abbrev # timeout=10
> git branch -D master # timeout=10
> git checkout -b master 1cbdd40467f475fcdbd8367ca00b65acbf774e3f # timeout=10
Commit message: "Merge pull request #99 from SonarSource/pre-8.x-hardening"
> git rev-list --no-walk 1cbdd40467f475fcdbd8367ca00b65acbf774e3f # timeout=10
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (SonarQube analysis)
[Pipeline] tool
[Pipeline] withSonarQubeEnv
Injecting SonarQube environment variables using the configuration: sonarqube-server
[Pipeline] {
[Pipeline] sh
+ /var/jenkins_home/tools/hudson.plugins.sonar.SonarRunnerInstallation/sonarqube/bin/sonar-scanner -D sonar.login=admin -D sonar.password=admin -D sonar.projectKey=sonarqubetest3 -D sonar.exclusions=vendor/**,resources/**,**/*.java -D sonar.host.url=http://192.168.0.4:9000
INFO: Scanner configuration file: /var/jenkins_home/tools/hudson.plugins.sonar.SonarRunnerInstallation/sonarqube/conf/sonar-scanner.properties
INFO: Project root configuration file: NONE
INFO: SonarScanner 4.5.0.2216
INFO: Java 1.8.0_242 Oracle Corporation (64-bit)
INFO: Linux 4.15.0-111-generic amd64
INFO: User cache: /var/jenkins_home/.sonar/cache
INFO: Scanner configuration file: /var/jenkins_home/tools/hudson.plugins.sonar.SonarRunnerInstallation/sonarqube/conf/sonar-scanner.properties
INFO: Project root configuration file: NONE
INFO: Analyzing on SonarQube server 8.6.0
INFO: Default locale: "en", source code encoding: "UTF-8" (analysis is platform dependent)
WARN: SonarScanner will require Java 11 to run starting in SonarQube 8.x
INFO: Load global settings
INFO: Load global settings (done) | time=658ms
INFO: Server id: BF41A1F2-AXaTGa1I2xlvXb1FgNjK
INFO: User cache: /var/jenkins_home/.sonar/cache
INFO: Load/download plugins
INFO: Load plugins index
INFO: Load plugins index (done) | time=602ms
INFO: Load/download plugins (done) | time=649ms
INFO: Process project properties
INFO: Process project properties (done) | time=1ms
INFO: Execute project builders
INFO: Execute project builders (done) | time=2ms
INFO: Project key: sonarqubetest3
INFO: Base dir: /var/jenkins_home/workspace/sonar-qube-testing
INFO: Working dir: /var/jenkins_home/workspace/sonar-qube-testing/.scannerwork
INFO: Load project settings for component key: 'sonarqubetest3'
INFO: Load project settings for component key: 'sonarqubetest3' (done) | time=574ms
INFO: Load quality profiles
INFO: Load quality profiles (done) | time=636ms
INFO: Auto-configuring with CI 'Jenkins'
INFO: Load active rules
INFO: Load active rules (done) | time=10366ms
INFO: Indexing files...
INFO: Project configuration:
INFO: Excluded sources: vendor/**, resources/**, **/*.java
INFO: Load project repositories
INFO: Load project repositories (done) | time=573ms
INFO: 105 files indexed
INFO: 12 files ignored because of inclusion/exclusion patterns
INFO: 0 files ignored because of scm ignore settings
INFO: Quality profile for cs: Sonar way
INFO: Quality profile for flex: Sonar way
INFO: Quality profile for js: Sonar way
INFO: Quality profile for kotlin: Sonar way
INFO: Quality profile for php: Sonar way
INFO: Quality profile for py: Sonar way
INFO: Quality profile for web: Sonar way
INFO: Quality profile for xml: Sonar way
INFO: ------------- Run sensors on module sonarqubetest3
INFO: Load metrics repository
INFO: Load metrics repository (done) | time=600ms
INFO: Sensor Python Sensor [python]
INFO: Starting global symbols computation
INFO: 9 source files to be analyzed
INFO: Starting rules execution
INFO: 9 source files to be analyzed
INFO: 9/9 source files have been analyzed
INFO: Sensor Python Sensor [python] (done) | time=6536ms
INFO: 9/9 source files have been analyzed
INFO: Sensor Cobertura Sensor for Python coverage [python]
INFO: Sensor Cobertura Sensor for Python coverage [python] (done) | time=23ms
INFO: Sensor PythonXUnitSensor [python]
INFO: Sensor PythonXUnitSensor [python] (done) | time=8ms
INFO: Sensor CSS Rules [cssfamily]
INFO: 2 source files to be analyzed
INFO: 2/2 source files have been analyzed
INFO: Sensor CSS Rules [cssfamily] (done) | time=1624ms
INFO: Sensor JaCoCo XML Report Importer [jacoco]
INFO: 'sonar.coverage.jacoco.xmlReportPaths' is not defined. Using default locations: target/site/jacoco/jacoco.xml,target/site/jacoco-it/jacoco.xml,build/reports/jacoco/test/jacocoTestReport.xml
INFO: No report imported, no coverage information will be imported by JaCoCo XML Report Importer
INFO: Sensor JaCoCo XML Report Importer [jacoco] (done) | time=6ms
INFO: Sensor Kotlin Sensor [kotlin]
INFO: 1 source files to be analyzed
INFO: Sensor Kotlin Sensor [kotlin] (done) | time=902ms
INFO: Sensor KotlinSurefireSensor [kotlin]
INFO: 1/1 source files have been analyzed
INFO: parsing [/var/jenkins_home/workspace/sonar-qube-testing/target/surefire-reports]
INFO: Sensor KotlinSurefireSensor [kotlin] (done) | time=5ms
INFO: Sensor JavaScript analysis [javascript]
INFO: 1 source files to be analyzed
INFO: Version of TypeScript used during analysis: 3.8.3
INFO: 1/1 source files have been analyzed
INFO: Sensor JavaScript analysis [javascript] (done) | time=4872ms
INFO: Sensor C# Properties [csharp]
INFO: Sensor C# Properties [csharp] (done) | time=1ms
INFO: Sensor JavaXmlSensor [java]
INFO: 8 source files to be analyzed
INFO: Sensor JavaXmlSensor [java] (done) | time=396ms
INFO: 8/8 source files have been analyzed
INFO: Sensor HTML [web]
INFO: Sensor HTML [web] (done) | time=80ms
INFO: Sensor Flex [flex]
INFO: 2 source files to be analyzed
INFO: Sensor Flex [flex] (done) | time=107ms
INFO: 2/2 source files have been analyzed
INFO: Sensor Flex Cobertura [flex]
INFO: No Cobertura report provided (see 'sonar.flex.cobertura.reportPaths' property)
INFO: Sensor Flex Cobertura [flex] (done) | time=1ms
INFO: Sensor XML Sensor [xml]
INFO: 8 source files to be analyzed
INFO: 8/8 source files have been analyzed
INFO: Sensor XML Sensor [xml] (done) | time=182ms
INFO: Sensor PHP sensor [php]
INFO: Starting PHP symbol indexer
INFO: 1 source files to be analyzed
INFO: 1/1 source files have been analyzed
INFO: Starting PHP rules
INFO: 1 source files to be analyzed
INFO: 1/1 source files have been analyzed
INFO: No PHPUnit test report provided (see 'sonar.php.tests.reportPath' property)
INFO: No PHPUnit coverage reports provided (see 'sonar.php.coverage.reportPaths' property)
INFO: Sensor PHP sensor [php] (done) | time=353ms
INFO: Sensor Analyzer for "php.ini" files [php]
INFO: Sensor Analyzer for "php.ini" files [php] (done) | time=2ms
INFO: Sensor VB.NET Properties [vbnet]
INFO: Sensor VB.NET Properties [vbnet] (done) | time=1ms
INFO: ------------- Run sensors on project
INFO: Sensor C# [csharp]
WARN: No protobuf reports found. The C# files will not have highlighting and metrics.
WARN: No Roslyn issue reports were found. The C# files have not been analyzed.
WARN: Your project contains C# files which cannot be analyzed with the scanner you are using. To analyze C# or VB.NET, you must use the Scanner for MSBuild 4.x, see https://redirect.sonarsource.com/doc/install-configure-scanner-msbuild.html
INFO: Sensor C# [csharp] (done) | time=1ms
INFO: Sensor Zero Coverage Sensor
INFO: Sensor Zero Coverage Sensor (done) | time=16ms
INFO: CPD Executor 7 files had no CPD blocks
INFO: CPD Executor Calculating CPD for 8 files
INFO: CPD Executor CPD calculation finished (done) | time=28ms
INFO: Analysis report generated in 135ms, dir size=189 KB
INFO: Analysis report compressed in 77ms, zip size=70 KB
INFO: Analysis report uploaded in 581ms
INFO: ANALYSIS SUCCESSFUL, you can browse http://192.168.0.4:9000/dashboard?id=sonarqubetest3
INFO: Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
INFO: More about the report processing at http://192.168.0.4:9000/api/ce/task?id=AXbH8OKO2xlvXb1FgSam
INFO: Analysis total time: 37.408 s
INFO: ------------------------------------------------------------------------
INFO: EXECUTION SUCCESS
INFO: ------------------------------------------------------------------------
INFO: Total time: 39.822s
INFO: Final Memory: 93M/761M
INFO: ------------------------------------------------------------------------
[Pipeline] }
[Pipeline] // withSonarQubeEnv
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Quality Gates)
[Pipeline] sleep
Sleeping for 1 min 0 sec
[Pipeline] timeout
Timeout set to expire in 1 hr 0 min
[Pipeline] {
[Pipeline] waitForQualityGate
Checking status of SonarQube task 'AXbH8OKO2xlvXb1FgSam' on server 'sonarqube-server'
[Pipeline] }
[Pipeline] // timeout
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
org.sonarqube.ws.client.HttpException: Error 401 on http://192.168.0.4:9000/api/ce/task?id=AXbH8OKO2xlvXb1FgSam :
at org.sonarqube.ws.client.BaseResponse.failIfNotSuccessful(BaseResponse.java:36)
at hudson.plugins.sonar.client.HttpClient.getHttp(HttpClient.java:38)
at hudson.plugins.sonar.client.WsClient.getCETask(WsClient.java:51)
at org.sonarsource.scanner.jenkins.pipeline.WaitForQualityGateStep$Execution.checkTaskCompleted(WaitForQualityGateStep.java:234)
at org.sonarsource.scanner.jenkins.pipeline.WaitForQualityGateStep$Execution.start(WaitForQualityGateStep.java:171)
at org.jenkinsci.plugins.workflow.cps.DSL.invokeStep(DSL.java:286)
at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:179)
at org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.java:122)
at sun.reflect.GeneratedMethodAccessor1239.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1213)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1022)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:42)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:163)
at org.kohsuke.groovy.sandbox.GroovyInterceptor.onMethodCall(GroovyInterceptor.java:23)
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:157)
at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:161)
at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:165)
at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:135)
at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:135)
at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:135)
at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.methodCall(SandboxInvoker.java:17)
at WorkflowScript.run(WorkflowScript:19)
at ___cps.transform___(Native Method)
at com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:86)
at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:113)
at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixArg(FunctionCallBlock.java:83)
at sun.reflect.GeneratedMethodAccessor1236.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
at com.cloudbees.groovy.cps.impl.CollectionLiteralBlock$ContinuationImpl.dispatch(CollectionLiteralBlock.java:55)
at com.cloudbees.groovy.cps.impl.CollectionLiteralBlock$ContinuationImpl.item(CollectionLiteralBlock.java:45)
at sun.reflect.GeneratedMethodAccessor1659.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
at com.cloudbees.groovy.cps.impl.ConstantBlock.eval(ConstantBlock.java:21)
at com.cloudbees.groovy.cps.Next.step(Next.java:83)
at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:174)
at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:163)
at org.codehaus.groovy.runtime.GroovyCategorySupport$ThreadCategoryInfo.use(GroovyCategorySupport.java:129)
at org.codehaus.groovy.runtime.GroovyCategorySupport.use(GroovyCategorySupport.java:268)
at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:163)
at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.access$001(SandboxContinuable.java:18)
at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.run0(SandboxContinuable.java:51)
at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:185)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:400)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$400(CpsThreadGroup.java:96)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:312)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:276)
at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:67)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:131)
at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
at jenkins.security.ImpersonatingExecutorService$1.run(ImpersonatingExecutorService.java:59)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
I know "Error 401" means wrong credentials/Unauthorized but same creds are working at 2nd stage "SonarQube Analysis" of job build.
i have also added webhooks url for jenkins in sonarqube server as "http://192.168.0.4:8056/sonarqube-webhook/" but to no avail.
Can someone please help me out over here.
Thanks & Regards
When you use the "withSonarQubeEnv" pipeline step, it is expected that the string value provided matches the name of the SonarQube instance configured in Jenkins. In that configuration will be defined the sonarqube login credentials. If that string matches the SonarQube instance name, then the login credentials will be put into environment variables.
However, I believe this usually only expects to use the "token" authentication method, not the old-style "login" and "password" values. In the "token" method, the "SONAR_AUTH_TOKEN" environment variable is set to the "sonar.login" property, and the "sonar.password" value is just not set.
In fact, I don't believe the "task" api used inside the "waitForQualityGate" step can use anything but the "token" authentication method. To get this to work, you'll need to define a token value, and set that inside the Jenkins configuration for the SonarQube instance.
Although we don't do it this way in our builds, I believe if you call the "waitForQualityGate" step INSIDE the "withSonarQubeEnv" step, that will put the proper authentication token into the environment variable so "waitForQualityGate" can see it.
It's very handy to run a "sh" step, running the "env" command line, so you can see what variables are set in the environment at any particular time.
It's also good to read the "sonar-scanner" reference, which talks about these steps, at https://docs.sonarqube.org/latest/analysis/scan/sonarscanner-for-jenkins/#AnalyzingwithSonarQubeScannerforJenkins-AnalyzinginaJenkinspipeline .
use this
withSonarQubeEnv(credentialsId: 'your token')
I am trying to learn the basics of sonarqube, I have set it up on my jenkins pipeline (which uses MSBuild to compile the project) and the set a step to execute SonarQube but after reading and watching a few tutorials and the documentation itself I think I got a bit lost as when my pipeline finishes executing I go to my SonarQube server and I my project says The main branch has no lines of code.. I get the following log when running the sonarqube step on my jenkins:
00:10:43.369 Injecting SonarQube environment variables using the configuration: SonarQube
[Pipeline] {
[Pipeline] bat
00:10:43.653
00:10:43.653 C:\Users\anton\.jenkins\workspace\Boston>C:\Users\anton\.jenkins\tools\hudson.plugins.sonar.MsBuildSQRunnerInstallation\Sonnar_scanner\sonar-scanner-4.4.0.2170\bin\sonar-scanner.bat
00:10:43.653 INFO: Scanner configuration file: C:\Users\anton\.jenkins\tools\hudson.plugins.sonar.MsBuildSQRunnerInstallation\Sonnar_scanner\sonar-scanner-4.4.0.2170\bin\..\conf\sonar-scanner.properties
00:10:43.653 INFO: Project root configuration file: NONE
00:10:43.653 INFO: SonarScanner 4.4.0.2170
00:10:43.653 INFO: Java 1.8.0_261 Oracle Corporation (64-bit)
00:10:43.653 INFO: Windows 10 10.0 amd64
00:10:44.230 INFO: User cache: C:\WINDOWS\system32\config\systemprofile\.sonar\cache
00:10:44.230 INFO: Scanner configuration file: C:\Users\anton\.jenkins\tools\hudson.plugins.sonar.MsBuildSQRunnerInstallation\Sonnar_scanner\sonar-scanner-4.4.0.2170\bin\..\conf\sonar-scanner.properties
00:10:44.230 INFO: Project root configuration file: NONE
00:10:44.230 INFO: Analyzing on SonarQube server 8.5.1
00:10:44.230 INFO: Default locale: "es_ES", source code encoding: "UTF-8"
00:10:44.783 WARN: SonarScanner will require Java 11 to run starting in SonarQube 8.x
00:10:44.784 INFO: Load global settings
00:10:44.784 INFO: Load global settings (done) | time=40ms
00:10:44.784 INFO: Server id: BF41A1F2-AXWnoupqHjnRwWgEnmvK
00:10:44.784 INFO: User cache: C:\WINDOWS\system32\config\systemprofile\.sonar\cache
00:10:44.784 INFO: Load/download plugins
00:10:44.784 INFO: Load plugins index
00:10:44.784 INFO: Load plugins index (done) | time=26ms
00:10:44.784 INFO: Load/download plugins (done) | time=48ms
00:10:45.037 INFO: Process project properties
00:10:45.037 INFO: Process project properties (done) | time=6ms
00:10:45.037 INFO: Execute project builders
00:10:45.037 INFO: Execute project builders (done) | time=1ms
00:10:45.037 INFO: Project key: Boston
00:10:45.037 INFO: Base dir: C:\Users\anton\.jenkins\workspace\Boston
00:10:45.037 INFO: Working dir: C:\Users\anton\.jenkins\workspace\Boston\.scannerwork
00:10:45.301 INFO: Load project settings for component key: 'Boston'
00:10:45.301 INFO: Load project settings for component key: 'Boston' (done) | time=10ms
00:10:45.301 INFO: Load quality profiles
00:10:45.301 INFO: Load quality profiles (done) | time=27ms
00:10:45.301 INFO: Auto-configuring with CI 'Jenkins'
00:10:45.301 INFO: Load active rules
00:10:46.241 INFO: Load active rules (done) | time=787ms
00:10:46.241 INFO: Indexing files...
00:10:46.241 INFO: Project configuration:
00:10:46.241 INFO: 0 files indexed
00:10:46.241 INFO: ------------- Run sensors on module Boston
00:10:46.241 INFO: Load metrics repository
00:10:46.241 INFO: Load metrics repository (done) | time=12ms
00:10:46.807 INFO: Sensor CSS Rules [cssfamily]
00:10:46.807 INFO: No CSS, PHP, HTML or VueJS files are found in the project. CSS analysis is skipped.
00:10:46.807 INFO: Sensor CSS Rules [cssfamily] (done) | time=1ms
00:10:46.807 INFO: Sensor JaCoCo XML Report Importer [jacoco]
00:10:46.807 INFO: 'sonar.coverage.jacoco.xmlReportPaths' is not defined. Using default locations: target/site/jacoco/jacoco.xml,target/site/jacoco-it/jacoco.xml,build/reports/jacoco/test/jacocoTestReport.xml
00:10:46.807 INFO: No report imported, no coverage information will be imported by JaCoCo XML Report Importer
00:10:46.807 INFO: Sensor JaCoCo XML Report Importer [jacoco] (done) | time=1ms
00:10:46.807 INFO: Sensor C# Properties [csharp]
00:10:46.807 INFO: Sensor C# Properties [csharp] (done) | time=1ms
00:10:46.807 INFO: Sensor JavaXmlSensor [java]
00:10:46.807 INFO: Sensor JavaXmlSensor [java] (done) | time=0ms
00:10:46.807 INFO: Sensor VB.NET Properties [vbnet]
00:10:46.807 INFO: Sensor VB.NET Properties [vbnet] (done) | time=0ms
00:10:46.807 INFO: ------------- Run sensors on project
00:10:46.807 INFO: Sensor Zero Coverage Sensor
00:10:46.807 INFO: Sensor Zero Coverage Sensor (done) | time=0ms
00:10:46.807 INFO: SCM Publisher is disabled
00:10:46.807 INFO: CPD Executor Calculating CPD for 0 files
00:10:46.807 INFO: CPD Executor CPD calculation finished (done) | time=0ms
00:10:46.807 INFO: Analysis report generated in 48ms, dir size=82 KB
00:10:46.807 INFO: Analysis report compressed in 10ms, zip size=10 KB
00:10:47.060 INFO: Analysis report uploaded in 26ms
00:10:47.060 INFO: ANALYSIS SUCCESSFUL, you can browse http://localhost:9000/dashboard?id=Boston
00:10:47.060 INFO: Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
00:10:47.060 INFO: More about the report processing at http://localhost:9000/api/ce/task?id=AXWt8eSC9o0F9NdVJGJP
00:10:47.060 INFO: Executing post-job 'Final report'
00:10:47.060 INFO: Turn debug info on to get more details (sonar-scanner -X -Dsonar.verbose=true ...).
00:10:47.060 INFO: Analysis total time: 2.118 s
00:10:47.060 INFO: ------------------------------------------------------------------------
00:10:47.060 INFO: EXECUTION SUCCESS
00:10:47.060 INFO: ------------------------------------------------------------------------
00:10:47.060 INFO: Total time: 3.274s
00:10:47.060 INFO: Final Memory: 21M/549M
00:10:47.060 INFO: ------------------------------------------------------------------------
[Pipeline] }
[Pipeline] // withSonarQubeEnv
[Pipeline] }
[Pipeline] // script
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // timestamps
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS
and I think the main issue is the line where it says Project root configuration file: NONE I have created a sonar-project.properties file in the root folder of my project and it has the following configuration:
sonar.projectKey=Boston
sonar.projectName=Boston
sonar.dotnet.visualStudio.solution=Age3DE.sln
sonar.scm.disabled=true
sonar.sources=./Source
sonar.language=c++
sonar.sourceEncoding=UTF-8
But yet I cannot make it work. I do not know what I am doing wrong, should the sonar-project.properties be set anywhere else?
If the source files are present in Sources directory, then your sonar.sources should be like this
sonar.sources=**/Sources/*
Or
sonar.sources=Sources/*
Please help me How to resolve this issue -
Getting Error while Sending Code from Jenkins to SonarQube.
git rev-list --no-walk 0070e5865725fdacc46d8444385e337eb9e6c4c8 # timeout=10
Unpacking https://repo1.maven.org/maven2/org/sonarsource/scanner/cli/sonar-scanner-cli/4.2.0.1873/sonar-scanner-cli-4.2.0.1873.zip to /jenkins/tools/hudson.plugins.sonar.SonarRunnerInstallation/ADOP_Sonar on 00a4ea1e
[Generali] $ /jenkins/tools/hudson.plugins.sonar.SonarRunnerInstallation/ADOP_Sonar/bin/sonar-scanner -X -Dsonar.host.url=https://alm.accenture.com/sonar -Dsonar.language=java "-Dsonar.projectName=Connected Vehicle Platform Sonar" -Dsonar.sourceEncoding=UTF-8 -Dsonar.projectKey=adop:CVPIFBNE:cvp -Dsonar.java.binaries=target/classes -Dsonar.sources=src/main/java -Dsonar.projectBaseDir=C:/Jenkins/workspace/Generali
14:30:02.030 INFO: Scanner configuration file: /jenkins/tools/hudson.plugins.sonar.SonarRunnerInstallation/ADOP_Sonar/conf/sonar-scanner.properties
14:30:02.038 INFO: Project root configuration file: NONE
14:30:02.147 INFO: SonarQube Scanner 4.2.0.1873
14:30:02.147 INFO: Java 9 Oracle Corporation (64-bit)
14:30:02.147 INFO: Linux 3.10.0-957.12.2.el7.x86_64 amd64
14:30:02.147 INFO: SONAR_SCANNER_OPTS=-Dsonar.login=04bcf7a2d5c6a5d44d9763fd840e723cbc85bb7e
14:30:02.641 DEBUG: keyStore is :
14:30:02.642 DEBUG: keyStore type is : pkcs12
14:30:02.642 DEBUG: keyStore provider is :
14:30:02.642 DEBUG: init keystore
14:30:02.643 DEBUG: init keymanager of type SunX509
14:30:02.897 DEBUG: Create: /root/.sonar/cache
14:30:02.899 INFO: User cache: /root/.sonar/cache
14:30:02.899 DEBUG: Create: /root/.sonar/cache/_tmp
14:30:02.904 DEBUG: Extract sonar-scanner-api-batch in temp...
14:30:02.911 DEBUG: Get bootstrap index...
14:30:02.911 DEBUG: Download: https://alm.accenture.com/sonar/batch/index
14:30:03.208 DEBUG: Get bootstrap completed
14:30:03.215 DEBUG: Download https://alm.accenture.com/sonar/batch/file?name=scanner-enterprise-7.9.1-all.jar to /root/.sonar/cache/_tmp/fileCache9893797395313049837.tmp
14:30:05.187 DEBUG: Create isolated classloader...
14:30:05.215 DEBUG: Start temp cleaning...
14:30:05.221 DEBUG: Temp cleaning done
14:30:05.222 DEBUG: Execution getVersion
14:30:05.237 INFO: SonarQube server 7.9.1
14:30:05.238 INFO: Default locale: "en", source code encoding: "UTF-8"
14:30:05.240 INFO: ------------------------------------------------------------------------
14:30:05.240 INFO: EXECUTION FAILURE
14:30:05.240 INFO: ------------------------------------------------------------------------
14:30:05.241 INFO: Total time: 3.298s
14:30:05.291 INFO: Final Memory: 3M/14M
14:30:05.291 INFO: ------------------------------------------------------------------------
14:30:05.291 ERROR: Error during SonarQube Scanner execution
java.lang.IllegalStateException: Project home must be an existing directory: /C:/Jenkins/workspace/Generali/C:/Jenkins/workspace/Generali
at org.sonarsource.scanner.api.Dirs.initProjectDirs(Dirs.java:51)
at org.sonarsource.scanner.api.Dirs.init(Dirs.java:41)
at org.sonarsource.scanner.api.EmbeddedScanner.initAnalysisProperties(EmbeddedScanner.java:158)
at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:137)
at org.sonarsource.scanner.cli.Main.execute(Main.java:112)
at org.sonarsource.scanner.cli.Main.execute(Main.java:75)
at org.sonarsource.scanner.cli.Main.main(Main.java:61)
WARN: Unable to locate 'report-task.txt' in the workspace. Did the SonarScanner succeeded?
ERROR: SonarQube scanner exited with non-zero code: 1
Finished: FAILURE
I had a similar issue:
ERROR: Error during SonarQube Scanner execution
ERROR: Project home must be an existing directory: C:\Windows\system32\config\...blah blah blah
I initially set my sonar.projectBaseDir by copying and pasting the path from File Explorer. The issue was Windows uses backslashes for paths. Once I switched them to forward slashes, the issue was fixed for me.
Context:
Right now I have a Jenkins freestyle job that is triggered by some Gerrit events. When it is triggered, it downloads the changes and runs a Sonarqube Analysis on them. After the analysis is done, it is supposed to post comments on Gerrit detailing the results.
Unfortunately, no matter what the result of the Sonarqube analysis, the comment always says "sonarqube violations have not been found."
Some pictures:
Jenkins Freestyle Job Configuration:
Versions:
Jenkins v2.46.2
Gerrit Trigger Plugin v.2.24.0
Sonar Gerrit Plugin v2.0
Sonarqube Scanner for Jenkins Plugin v2.6.1
Sonarqube v6.3.1
Gerrit v2.13.5
Output from the Jenkins console:
Unpacking https://repo1.maven.org/maven2/org/sonarsource/scanner/cli/sonar-scanner-cli/3.0.3.778/sonar-scanner-cli-3.0.3.778.zip to /var/jenkins/tools/hudson.plugins.sonar.SonarRunnerInstallation/sonar on ubuntu-graphical
[osstp-ci] $ /var/jenkins/tools/hudson.plugins.sonar.SonarRunnerInstallation/sonar/bin/sonar-scanner -e -Dsonar.host.url=<ip_address>:9000 -Dsonar.projectName=osstp-work -Dsonar.issuesReport.json.enable=true -Dsonar.report.export.path=sonar-report.json -Dsonar.analysis.mode=preview -Dsonar.projectKey=org.vmware:osstpmgt -Dsonar.inclusions=**/*.py -Dsonar.host.url=http://10.20.96.87:9000 -Dsonar.sources=. -Dsonar.projectBaseDir=/var/jenkins/workspace/osstp-ci
INFO: Option -e/--errors is no longer supported and will be ignored
INFO: Scanner configuration file: /var/jenkins/tools/hudson.plugins.sonar.SonarRunnerInstallation/sonar/conf/sonar-scanner.properties
INFO: Project root configuration file: NONE
INFO: SonarQube Scanner 3.0.3.778
INFO: Java 1.8.0_131 Oracle Corporation (64-bit)
INFO: Linux 4.8.0-36-generic amd64
INFO: User cache: /home/tgong/.sonar/cache
INFO: Load global settings
INFO: Load global settings (done) | time=160ms
INFO: User cache: /home/tgong/.sonar/cache
INFO: Exclude plugins: devcockpit, ldap, authgithub, authbitbucket, pdfreport, authaad, googleanalytics, governance
INFO: Load plugins index
INFO: Load plugins index (done) | time=10ms
INFO: Download sonar-csharp-plugin-5.7.0.612.jar
INFO: Download sonar-python-plugin-1.7.0.1195.jar
INFO: Download sonar-java-plugin-4.5.0.8398.jar
INFO: Download sonar-flex-plugin-2.3.jar
INFO: Download sonar-scm-git-plugin-1.2.jar
INFO: Download sonar-php-plugin-2.9.2.1744.jar
INFO: Download sonar-scm-svn-plugin-1.4.0.522.jar
INFO: Download sonar-javascript-plugin-2.20.0.4207.jar
INFO: SonarQube server 6.3.1
INFO: Default locale: "en_US", source code encoding: "UTF-8" (analysis is platform dependent)
INFO: Process project properties
INFO: Load project repositories
INFO: Load project repositories (done) | time=217ms
INFO: Load quality profiles
INFO: Load quality profiles (done) | time=66ms
INFO: Load active rules
INFO: Load active rules (done) | time=1693ms
INFO: Load metrics repository
INFO: Load metrics repository (done) | time=141ms
INFO: Issues mode
INFO: Scanning only changed files
INFO: Project key: org.vmware:osstpmgt
INFO: ------------- Scan osstp-work
INFO: Load server rules
INFO: Load server rules (done) | time=68ms
INFO: Base dir: /var/jenkins/workspace/osstp-ci
INFO: Working dir: /var/jenkins/workspace/osstp-ci/.scannerwork
INFO: Source paths: .
INFO: Source encoding: UTF-8, default locale: en_US
INFO: Index files
INFO: Included sources:
INFO: **/*.py
WARN: Not indexing due to symlink loop: /var/jenkins/workspace/osstp-ci/www/scotzilla
INFO: 717 files indexed
INFO: 2093 files ignored because of inclusion/exclusion patterns
INFO: Quality profile for py: Sonar way
INFO: Sensor NoSonar Sensor [php]
INFO: Sensor NoSonar Sensor [php] (done) | time=1ms
INFO: Sensor Coverage Report Import [csharp]
INFO: Sensor Coverage Report Import [csharp] (done) | time=1ms
INFO: Sensor Coverage Report Import [csharp]
INFO: Sensor Coverage Report Import [csharp] (done) | time=0ms
INFO: Sensor Unit Test Results Import [csharp]
INFO: Sensor Unit Test Results Import [csharp] (done) | time=1ms
INFO: Sensor XmlFileSensor [java]
INFO: Sensor XmlFileSensor [java] (done) | time=7ms
INFO: Sensor Analyzer for "php.ini" files [php]
INFO: Sensor Analyzer for "php.ini" files [php] (done) | time=8ms
INFO: Load server issues
INFO: Load server issues (done) | time=1053ms
INFO: Performing issue tracking
INFO: 813/813 components tracked
INFO: Export issues to /var/jenkins/workspace/osstp-ci/.scannerwork/sonar-report.json
INFO: ANALYSIS SUCCESSFUL
INFO: Task total time: 11.610 s
INFO: ------------------------------------------------------------------------
INFO: EXECUTION SUCCESS
INFO: ------------------------------------------------------------------------
INFO: Total time: 17.577s
INFO: Final Memory: 46M/114M
INFO: ------------------------------------------------------------------------
Getting Sonar Report from: /var/jenkins/workspace/osstp-ci/.scannerwork/sonar-report.json
Report has loaded and contains 1492 issues
Connected to Gerrit: server name: Gerrit. Change Number: 32, PatchSetNumber: 1
Review has been sent
Finished: SUCCESS
Not sure if you already resolved this, but your "Project Settings" entry is empty and there was a recent fix (Jan 2018 - JENKINS-43730) that addresses what may have caused your issue: https://wiki.jenkins.io/display/JENKINS/Sonar+Gerrit#SonarGerrit-Version2.1(6Jan2018)
Try to set the following:
1) Build > Execute SonarQube Scanner > Analysis properties
sonar.report.export.path=sonar-report.json
2) Post-build Actions > Post SonarQube issues as Gerrit comments > Project Settings
SonarQube report path = .sonar/sonar-report.json
Seems like your user.dir property is not set. Set it to the location where git downloads the code (most probably in $WORKSPACE)
so, include this user.dir=$WORKSPACE with the other analysis parameters.