Adding SonarQube to a C++ build on Jenkins

  • ALM used: Bitbucket Cloud
  • CI system used: Jenkins
  • Languages of the repository: C++

I’m trying to add SonarQube integration to our Jenkins build server. I followed the instructions from our in-house server to setup Jenkins then downloaded sonarqube-build-wrapper-linux-x86.zip and installed the files on the build agent in the PATH. We’re using a multibranch pipeline build configured by Jenkinsfile in the source repo so I setup a test branch with:

        stage('SonarQube analysis') {
            def scannerHome = tool 'SonarScanner 4.0'
            withSonarQubeEnv() {
                sh "${scannerHome}/bin/sonar-scanner"
            }
        }

But there doesn’t seem to be a sonar-scanner executable installed. sonarqube-build-wrapper-linux-x86.zip contains:

  • build-wrapper-linux-x86-64
  • libinterceptor-haswell.so
  • libinterceptor-i686.so
  • libinterceptor-x86_64.so

and I can run build-wrapper-linux-x86-64 -h fine. Is sonar-scanner supposed to be included in the zip?
Also, this code doesn’t work in Jenkins - I get:

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 29: Not a valid stage section definition: "def scannerHome = tool 'SonarScanner 4.0'". Some extra configuration is required. @ line 29, column 9.
           stage('SonarQube analysis') {
           ^

WorkflowScript: 29: Unknown stage section "withSonarQubeEnv". Starting with version 0.5, steps in a stage must be in a ‘steps’ block. @ line 29, column 9.
           stage('SonarQube analysis') {
           ^

WorkflowScript: 29: Expected one of "steps", "stages", or "parallel" for stage "SonarQube analysis" @ line 29, column 9.
           stage('SonarQube analysis') {
           ^

3 errors

I tried wrapping it in steps so:

        stage('SonarQube analysis') {
            steps {
                def scannerHome = tool 'SonarScanner 4.0'
                withSonarQubeEnv() {
                    sh "${scannerHome}/bin/sonar-scanner"
                }
            }
        }

but this fails with:

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 31: Expected a step @ line 31, column 17.
                   def scannerHome = tool 'SonarScanner 4.0'
                   ^

WorkflowScript: 32: Missing required parameter: "installationName" @ line 32, column 17.
                   withSonarQubeEnv() {
                   ^

2 errors

There’s a lot of contradictory advice on this, would be good to have a simple example to follow.

Looking around some of the previous questions here made me realise that build-wrapper-linux-x86-64 is literally a build wrapper, so should be used like this:

mkdir -p build_wrapper_output_directory
build-wrapper-linux-x86-64 --out-dir build_wrapper_output_directory ./build.sh

This is working for me now, and I’m seeing the build_wrapper_output_directory contain build-wrapper-dump.json and build-wrapper.log.

But I still can’t run sonar-scanner. Where is this supposed to come from?

1 Like

Hi,

Yes, the build-wrapper and the scanner are two separate pieces, and the build-wrapper is only needed for projects containing C, C++ or Objective-C.

The docs will get you started with the scanner.

 
HTH,
Ann

I’ve followed the docs:
I’m using Jenkins so Jenkins extension for SonarQube

  1. Install the Jenkins Extension for SonarQube via the Jenkins Update Center.
  2. Configure your SonarQube server.

Then Jenkins extension for SonarQube - Analyzing other project types

But sonar-scanner still isn’t present. What am I missing?

I tried adding the example to my Jenkinsfile:

        stage('SonarQube analysis') {
            steps {
                withSonarQubeEnv('My SonarQube Server', envOnly: true) {
                    // This expands the evironment variables SONAR_CONFIG_NAME, SONAR_HOST_URL, SONAR_AUTH_TOKEN that can be used by any script.
                    println ${ env.SONAR_HOST_URL }
                }
            }
        }

but I get:

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 32: ${ env.SONAR_HOST_URL } cannot be used as a value directly. Did you mean "${ env.SONAR_HOST_URL }"? (add quotes) @ line 32, column 29.
                       println ${ env.SONAR_HOST_URL }
                               ^

WorkflowScript: 30: Arguments to "withSonarQubeEnv" must be explicitly named. @ line 30, column 17.
                   withSonarQubeEnv('My SonarQube Server', envOnly: true) {
                   ^

2 errors

Hi,

That sends you to the SonarQube docs. Did you follow this part of that documentation, where it tells you to

Scroll down to the SonarScanner configuration section and click on Add SonarScanner.

?

 
Ann

Yes.

I assume “2. Add the SonarScanner build step to your build.” is adding the step to the Jenkinsfile?

Hi,

You mean this part?

  1. Scroll down to the SonarScanner configuration section and click on Add SonarScanner. It is based on the typical Jenkins tool auto-installation.

That’s the part where you use Jenkins to install the scanner on your build agent.

Or this?

  1. Add the SonarScanner build step to your build.

Yes, once you’ve installed a scanner on your build agent, then that’s the part where you configure its use in your pipeline.

 
Ann

For the installation “Install from Maven Central” has been automatically selected. Is that wrong?

Hi,

…Good point.

I think maybe the vanilla scanner - the one you need - used to be distributed to Maven Central, but probably not any more. I’m going to raise this to the docs team; we probably need to take a look at that.

In the meantime, you can download the scanner from here.

 
HTH,
Ann

I’ve changed Jenkins to install from the .zip listed on that page but it’s still failing to find sonar-scanner. Does the install get triggered by something like withSonarQubeEnv in Jenkinsfile? In which case what’s the format for this, because I keep getting errors when I try to add it.

Should I be able to see the .zip being installed in the Jenkins log?

Hi,

Can you try installing SonarScanner manually on your build agents following the install directions listed here, please?

 
Ann

I got this far:

11:09:18  INFO: Scanner configuration file: /usr/bin/sonar-scanner-5.0.1.3006-linux/conf/sonar-scanner.properties
11:09:18  INFO: Project root configuration file: /home/jenkins/workspace/add_sonarqube/sonar-project.properties
11:09:18  INFO: SonarScanner 5.0.1.3006
11:09:18  INFO: Java 17.0.7 Eclipse Adoptium (64-bit)
11:09:18  INFO: Linux 6.2.0-26-generic amd64
11:09:18  INFO: User cache: /home/jenkins/.sonar/cache
11:24:20  INFO: ------------------------------------------------------------------------
11:24:20  INFO: EXECUTION FAILURE
11:24:20  INFO: ------------------------------------------------------------------------
11:24:20  INFO: Total time: 14:54.731s
11:24:20  INFO: Final Memory: 11M/136M
11:24:20  INFO: ------------------------------------------------------------------------
11:24:20  ERROR: Error during SonarScanner execution
11:24:20  org.sonarsource.scanner.api.internal.ScannerException: Unable to execute SonarScanner analysis
11:24:20  	at org.sonarsource.scanner.api.internal.IsolatedLauncherFactory.lambda$createLauncher$0(IsolatedLauncherFactory.java:85)
11:24:20  	at java.base/java.security.AccessController.doPrivileged(Unknown Source)
11:24:20  	at org.sonarsource.scanner.api.internal.IsolatedLauncherFactory.createLauncher(IsolatedLauncherFactory.java:74)
11:24:20  	at org.sonarsource.scanner.api.internal.IsolatedLauncherFactory.createLauncher(IsolatedLauncherFactory.java:70)
11:24:20  	at org.sonarsource.scanner.api.EmbeddedScanner.doStart(EmbeddedScanner.java:185)
11:24:20  	at org.sonarsource.scanner.api.EmbeddedScanner.start(EmbeddedScanner.java:123)
11:24:20  	at org.sonarsource.scanner.cli.Main.execute(Main.java:74)
11:24:20  	at org.sonarsource.scanner.cli.Main.main(Main.java:62)
11:24:20  Caused by: java.lang.IllegalStateException: Fail to download scanner-enterprise-8.9.6.50800-all.jar to /home/jenkins/.sonar/cache/_tmp/fileCache8366279534839366149.tmp
11:24:20  	at org.sonarsource.scanner.api.internal.cache.FileCache.download(FileCache.java:100)
11:24:20  	at org.sonarsource.scanner.api.internal.cache.FileCache.get(FileCache.java:84)
11:24:20  	at org.sonarsource.scanner.api.internal.JarDownloader.lambda$getScannerEngineFiles$0(JarDownloader.java:60)
11:24:20  	at java.base/java.util.stream.ReferencePipeline$3$1.accept(Unknown Source)
11:24:20  	at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(Unknown Source)
11:24:20  	at java.base/java.util.stream.AbstractPipeline.copyInto(Unknown Source)
11:24:20  	at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)
11:24:20  	at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(Unknown Source)
11:24:20  	at java.base/java.util.stream.AbstractPipeline.evaluate(Unknown Source)
11:24:20  	at java.base/java.util.stream.ReferencePipeline.collect(Unknown Source)
11:24:20  	at org.sonarsource.scanner.api.internal.JarDownloader.getScannerEngineFiles(JarDownloader.java:61)
11:24:20  	at org.sonarsource.scanner.api.internal.JarDownloader.download(JarDownloader.java:53)
11:24:20  	at org.sonarsource.scanner.api.internal.IsolatedLauncherFactory.lambda$createLauncher$0(IsolatedLauncherFactory.java:76)
11:24:20  	... 7 more
11:24:20  Caused by: org.sonarsource.scanner.api.internal.shaded.okhttp.internal.http2.StreamResetException: stream was reset: INTERNAL_ERROR
11:24:20  	at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.http2.Http2Stream$FramingSource.read(Http2Stream.java:384)
11:24:20  	at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.connection.Exchange$ResponseBodySource.read(Exchange.java:286)
11:24:20  	at org.sonarsource.scanner.api.internal.shaded.okio.RealBufferedSource$1.read(RealBufferedSource.java:447)
11:24:20  	at java.base/java.io.InputStream.transferTo(Unknown Source)
11:24:20  	at java.base/java.nio.file.Files.copy(Unknown Source)
11:24:20  	at org.sonarsource.scanner.api.internal.ServerConnection.downloadFile(ServerConnection.java:82)
11:24:20  	at org.sonarsource.scanner.api.internal.JarDownloader$ScannerFileDownloader.download(JarDownloader.java:73)
11:24:20  	at org.sonarsource.scanner.api.internal.cache.FileCache.download(FileCache.java:98)
11:24:20  	... 19 more
11:24:20  ERROR: 
11:24:20  ERROR: Re-run SonarScanner using the -X switch to enable full debug logging.

I found SonarQube scanner fails, 'Fail to download sonar-scanner-engine-shaded-7.2.1-all.jar' which suggested checking that https://sonarqube.company.com/batch/file?name=scanner-enterprise-8.9.6.50800-all.jar can be downloaded - it can.

Enabling debug gives me:

17:51:23  04:51:23.028 INFO: Scanner configuration file: /usr/bin/sonar-scanner-5.0.1.3006-linux/conf/sonar-scanner.properties
17:51:23  04:51:23.036 INFO: Project root configuration file: /home/jenkins/workspace/add_sonarqube/sonar-project.properties
17:51:23  04:51:23.050 INFO: SonarScanner 5.0.1.3006
17:51:23  04:51:23.051 INFO: Java 17.0.7 Eclipse Adoptium (64-bit)
17:51:23  04:51:23.051 INFO: Linux 6.2.0-26-generic amd64
17:51:23  04:51:23.132 DEBUG: keyStore is : 
17:51:23  04:51:23.132 DEBUG: keyStore type is : pkcs12
17:51:23  04:51:23.132 DEBUG: keyStore provider is : 
17:51:23  04:51:23.132 DEBUG: init keystore
17:51:23  04:51:23.133 DEBUG: init keymanager of type SunX509
17:51:23  04:51:23.191 DEBUG: Create: /home/jenkins/.sonar/cache
17:51:23  04:51:23.192 INFO: User cache: /home/jenkins/.sonar/cache
17:51:23  04:51:23.192 DEBUG: Create: /home/jenkins/.sonar/cache/_tmp
17:51:23  04:51:23.193 DEBUG: Extract sonar-scanner-api-batch in temp...
17:51:23  04:51:23.195 DEBUG: Get bootstrap index...
17:51:23  04:51:23.195 DEBUG: Download: https://sonarqube.company.com/batch/index
17:51:25  04:51:25.233 DEBUG: Get bootstrap completed
17:51:25  04:51:25.235 DEBUG: Download https://sonarqube.company.com/batch/file?name=scanner-enterprise-8.9.6.50800-all.jar to /home/jenkins/.sonar/cache/_tmp/fileCache3334011300596248088.tmp
17:57:07  04:56:59.346 DEBUG: Create isolated classloader...
17:57:07  04:56:59.353 DEBUG: Start temp cleaning...
17:57:07  04:56:59.355 DEBUG: Temp cleaning done
17:57:07  04:56:59.355 DEBUG: Execution getVersion
17:57:07  04:56:59.363 INFO: Analyzing on SonarQube server 8.9.6
17:57:07  04:56:59.364 INFO: Default locale: "en", source code encoding: "UTF-8"
17:57:07  04:56:59.364 DEBUG: Work directory: /home/jenkins/workspace/add_sonarqube/.scannerwork
17:57:07  04:56:59.365 DEBUG: Execution execute
17:57:07  04:56:59.481 DEBUG: Enterprise 8.9.6.50800
17:57:07  04:56:59.568 INFO: Load global settings
17:57:07  04:57:01.660 DEBUG: GET 401 https://sonarqube.company.com/api/settings/values.protobuf | time=2090ms
17:57:07  04:57:01.663 INFO: ------------------------------------------------------------------------
17:57:07  04:57:01.664 INFO: EXECUTION FAILURE
17:57:07  04:57:01.664 INFO: ------------------------------------------------------------------------
17:57:07  04:57:01.664 INFO: Total time: 5:38.647s
17:57:07  04:57:01.680 INFO: Final Memory: 13M/112M
17:57:07  04:57:01.680 INFO: ------------------------------------------------------------------------
17:57:07  04:57:01.680 ERROR: Error during SonarScanner execution
17:57:07  java.lang.IllegalStateException: Unable to load component class org.sonar.scanner.bootstrap.ScannerPluginInstaller
17:57:07  	at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:66)
17:57:07  	at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:632)
17:57:07  	at org.picocontainer.parameters.BasicComponentParameter$1.resolveInstance(BasicComponentParameter.java:118)
17:57:07  	at org.picocontainer.parameters.ComponentParameter$1.resolveInstance(ComponentParameter.java:136)
17:57:07  	at org.picocontainer.injectors.SingleMemberInjector.getParameter(SingleMemberInjector.java:78)
17:57:07  	at org.picocontainer.injectors.ConstructorInjector$CtorAndAdapters.getParameterArguments(ConstructorInjector.java:309)
17:57:07  	at org.picocontainer.injectors.ConstructorInjector$1.run(ConstructorInjector.java:335)
17:57:07  	at org.picocontainer.injectors.AbstractInjector$ThreadLocalCyclicDependencyGuard.observe(AbstractInjector.java:270)
17:57:07  	at org.picocontainer.injectors.ConstructorInjector.getComponentInstance(ConstructorInjector.java:364)
17:57:07  	at org.picocontainer.injectors.AbstractInjectionFactory$LifecycleAdapter.getComponentInstance(AbstractInjectionFactory.java:56)
17:57:07  	at org.picocontainer.behaviors.AbstractBehavior.getComponentInstance(AbstractBehavior.java:64)
17:57:07  	at org.picocontainer.behaviors.Stored.getComponentInstance(Stored.java:91)
17:57:07  	at org.picocontainer.DefaultPicoContainer.instantiateComponentAsIsStartable(DefaultPicoContainer.java:1034)
17:57:07  	at org.picocontainer.DefaultPicoContainer.addAdapterIfStartable(DefaultPicoContainer.java:1026)
17:57:07  	at org.picocontainer.DefaultPicoContainer.startAdapters(DefaultPicoContainer.java:1003)
17:57:07  	at org.picocontainer.DefaultPicoContainer.start(DefaultPicoContainer.java:767)
17:57:07  	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
17:57:07  	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:123)
17:57:07  	at org.sonar.batch.bootstrapper.Batch.doExecute(Batch.java:72)
17:57:07  	at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:66)
17:57:07  	at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
17:57:07  	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
17:57:07  	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
17:57:07  	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
17:57:07  	at java.base/java.lang.reflect.Method.invoke(Unknown Source)
17:57:07  	at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
17:57:07  	at jdk.proxy1/jdk.proxy1.$Proxy0.execute(Unknown Source)
17:57:07  	at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:189)
17:57:07  	at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:138)
17:57:07  	at org.sonarsource.scanner.cli.Main.execute(Main.java:126)
17:57:07  	at org.sonarsource.scanner.cli.Main.execute(Main.java:81)
17:57:07  	at org.sonarsource.scanner.cli.Main.main(Main.java:62)
17:57:07  Caused by: java.lang.IllegalStateException: Unable to load component class org.sonar.scanner.bootstrap.PluginFiles
17:57:07  	at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:66)
17:57:07  	at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:632)
17:57:07  	at org.picocontainer.parameters.BasicComponentParameter$1.resolveInstance(BasicComponentParameter.java:118)
17:57:07  	at org.picocontainer.parameters.ComponentParameter$1.resolveInstance(ComponentParameter.java:136)
17:57:07  	at org.picocontainer.injectors.SingleMemberInjector.getParameter(SingleMemberInjector.java:78)
17:57:07  	at org.picocontainer.injectors.ConstructorInjector$CtorAndAdapters.getParameterArguments(ConstructorInjector.java:309)
17:57:07  	at org.picocontainer.injectors.ConstructorInjector$1.run(ConstructorInjector.java:335)
17:57:07  	at org.picocontainer.injectors.AbstractInjector$ThreadLocalCyclicDependencyGuard.observe(AbstractInjector.java:270)
17:57:07  	at org.picocontainer.injectors.ConstructorInjector.getComponentInstance(ConstructorInjector.java:364)
17:57:07  	at org.picocontainer.injectors.AbstractInjectionFactory$LifecycleAdapter.getComponentInstance(AbstractInjectionFactory.java:56)
17:57:07  	at org.picocontainer.behaviors.AbstractBehavior.getComponentInstance(AbstractBehavior.java:64)
17:57:07  	at org.picocontainer.behaviors.Stored.getComponentInstance(Stored.java:91)
17:57:07  	at org.picocontainer.DefaultPicoContainer.getInstance(DefaultPicoContainer.java:699)
17:57:07  	at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:647)
17:57:07  	at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:64)
17:57:07  	... 31 more
17:57:07  Caused by: java.lang.IllegalStateException: Unable to load component class org.sonar.scanner.bootstrap.GlobalConfiguration
17:57:07  	at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:66)
17:57:07  	at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:632)
17:57:07  	at org.picocontainer.parameters.BasicComponentParameter$1.resolveInstance(BasicComponentParameter.java:118)
17:57:07  	at org.picocontainer.parameters.ComponentParameter$1.resolveInstance(ComponentParameter.java:136)
17:57:07  	at org.picocontainer.injectors.SingleMemberInjector.getParameter(SingleMemberInjector.java:78)
17:57:07  	at org.picocontainer.injectors.ConstructorInjector$CtorAndAdapters.getParameterArguments(ConstructorInjector.java:309)
17:57:07  	at org.picocontainer.injectors.ConstructorInjector$1.run(ConstructorInjector.java:335)
17:57:07  	at org.picocontainer.injectors.AbstractInjector$ThreadLocalCyclicDependencyGuard.observe(AbstractInjector.java:270)
17:57:07  	at org.picocontainer.injectors.ConstructorInjector.getComponentInstance(ConstructorInjector.java:364)
17:57:07  	at org.picocontainer.injectors.AbstractInjectionFactory$LifecycleAdapter.getComponentInstance(AbstractInjectionFactory.java:56)
17:57:07  	at org.picocontainer.behaviors.AbstractBehavior.getComponentInstance(AbstractBehavior.java:64)
17:57:07  	at org.picocontainer.behaviors.Stored.getComponentInstance(Stored.java:91)
17:57:07  	at org.picocontainer.DefaultPicoContainer.getInstance(DefaultPicoContainer.java:699)
17:57:07  	at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:647)
17:57:07  	at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:64)
17:57:07  	... 45 more
17:57:07  Caused by: java.lang.IllegalStateException: Unable to load component class org.sonar.scanner.bootstrap.GlobalServerSettings
17:57:07  	at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:66)
17:57:07  	at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:632)
17:57:07  	at org.picocontainer.parameters.BasicComponentParameter$1.resolveInstance(BasicComponentParameter.java:118)
17:57:07  	at org.picocontainer.parameters.ComponentParameter$1.resolveInstance(ComponentParameter.java:136)
17:57:07  	at org.picocontainer.injectors.SingleMemberInjector.getParameter(SingleMemberInjector.java:78)
17:57:07  	at org.picocontainer.injectors.SingleMemberInjector.getMemberArguments(SingleMemberInjector.java:61)
17:57:07  	at org.picocontainer.injectors.MethodInjector.getMemberArguments(MethodInjector.java:100)
17:57:07  	at org.picocontainer.injectors.MethodInjector$2.run(MethodInjector.java:112)
17:57:07  	at org.picocontainer.injectors.AbstractInjector$ThreadLocalCyclicDependencyGuard.observe(AbstractInjector.java:270)
17:57:07  	at org.picocontainer.injectors.MethodInjector.decorateComponentInstance(MethodInjector.java:120)
17:57:07  	at org.picocontainer.injectors.CompositeInjector.decorateComponentInstance(CompositeInjector.java:58)
17:57:07  	at org.picocontainer.injectors.Reinjector.reinject(Reinjector.java:142)
17:57:07  	at org.picocontainer.injectors.ProviderAdapter.getComponentInstance(ProviderAdapter.java:96)
17:57:07  	at org.picocontainer.DefaultPicoContainer.getInstance(DefaultPicoContainer.java:699)
17:57:07  	at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:647)
17:57:07  	at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:64)
17:57:07  	... 59 more
17:57:07  Caused by: Not authorized. Analyzing this project requires authentication. Please provide a user token in sonar.login or other credentials in sonar.login and sonar.password.

I thought this was already setup in Jenkins?

Hi,

You’ve configured a server connection at the global level? And only one? If so, it’s likely that the token you provided in that configuration isn’t authorized for the project you’re trying to analyze.

 
Ann

Yes, and I’ve only got one project. I don’t think the key is being passed to the instance, how can I check? What value is sonar-scanner reading from the environment?

Ended up hardcoding the token to get it to work and now it fails trying to download a whole pile of plugins I don’t need (this is just a C++ build):

13:44:24  00:44:23.945 INFO: Scanner configuration file: /usr/bin/sonar-scanner-5.0.1.3006-linux/conf/sonar-scanner.properties
13:44:24  00:44:23.952 INFO: Project root configuration file: /home/jenkins/workspace/l6q_add_sonarqube/sonar-project.properties
13:44:24  00:44:23.966 INFO: SonarScanner 5.0.1.3006
13:44:24  00:44:23.966 INFO: Java 17.0.7 Eclipse Adoptium (64-bit)
13:44:24  00:44:23.966 INFO: Linux 6.2.0-26-generic amd64
13:44:24  00:44:24.044 DEBUG: keyStore is : 
13:44:24  00:44:24.044 DEBUG: keyStore type is : pkcs12
13:44:24  00:44:24.044 DEBUG: keyStore provider is : 
13:44:24  00:44:24.044 DEBUG: init keystore
13:44:24  00:44:24.044 DEBUG: init keymanager of type SunX509
13:44:24  00:44:24.098 DEBUG: Create: /home/jenkins/.sonar/cache
13:44:24  00:44:24.098 INFO: User cache: /home/jenkins/.sonar/cache
13:44:24  00:44:24.098 DEBUG: Create: /home/jenkins/.sonar/cache/_tmp
13:44:24  00:44:24.099 DEBUG: Extract sonar-scanner-api-batch in temp...
13:44:24  00:44:24.101 DEBUG: Get bootstrap index...
13:44:24  00:44:24.101 DEBUG: Download: https://sonarqube.company.com/batch/index
13:44:26  00:44:26.143 DEBUG: Get bootstrap completed
13:44:26  00:44:26.144 DEBUG: Download https://sonarqube.company.com/batch/file?name=scanner-enterprise-8.9.6.50800-all.jar to /home/jenkins/.sonar/cache/_tmp/fileCache732581920912186291.tmp
13:48:37  00:48:25.413 DEBUG: Create isolated classloader...
13:48:37  00:48:25.419 DEBUG: Start temp cleaning...
13:48:37  00:48:25.421 DEBUG: Temp cleaning done
13:48:37  00:48:25.421 DEBUG: Execution getVersion
13:48:37  00:48:25.428 INFO: Analyzing on SonarQube server 8.9.6
13:48:37  00:48:25.428 INFO: Default locale: "en", source code encoding: "UTF-8"
13:48:37  00:48:25.428 DEBUG: Work directory: /home/jenkins/workspace/orola_motorola-l6q_add_sonarqube/.scannerwork
13:48:37  00:48:25.429 DEBUG: Execution execute
13:48:37  00:48:25.537 DEBUG: Enterprise 8.9.6.50800
13:48:37  00:48:25.619 INFO: Load global settings
13:48:37  00:48:27.802 DEBUG: GET 200 https://sonarqube.company.com/api/settings/values.protobuf | time=2182ms
13:48:37  00:48:27.817 INFO: Load global settings (done) | time=2198ms
13:48:37  00:48:27.819 INFO: Server id: 723A1A45-1e9fcd5932eb852
13:48:37  00:48:27.820 DEBUG: Create : /home/jenkins/.sonar/_tmp
13:48:37  00:48:27.820 INFO: User cache: /home/jenkins/.sonar/cache
13:48:37  00:48:27.822 INFO: Load/download plugins
13:48:37  00:48:27.822 INFO: Load plugins index
13:48:37  00:48:28.112 DEBUG: GET 200 https://sonarqube.company.com/api/plugins/installed | time=290ms
13:48:37  00:48:28.131 INFO: Load plugins index (done) | time=309ms
13:48:37  00:48:28.131 DEBUG: Download plugin 'abap' to '/home/jenkins/.sonar/_tmp/fileCache5555170327893440113.tmp'
13:48:37  00:48:28.424 DEBUG: GET 200 https://sonarqube.company.com/api/plugins/download?plugin=abap | time=293ms
13:48:40  00:48:39.594 DEBUG: Download plugin 'sonarapex' to '/home/jenkins/.sonar/_tmp/fileCache7673064186110735800.tmp'
13:48:40  00:48:39.899 DEBUG: GET 200 https://sonarqube.company.com/api/plugins/download?plugin=sonarapex | time=305ms
13:49:14  00:49:09.984 DEBUG: Download plugin 'csharp' to '/home/jenkins/.sonar/_tmp/fileCache1579381522799354734.tmp'
13:49:14  00:49:10.278 DEBUG: GET 200 https://sonarqube.company.com/api/plugins/download?plugin=csharp | time=294ms
13:50:39  00:50:29.128 DEBUG: Download plugin 'cpp' to '/home/jenkins/.sonar/_tmp/fileCache13064576973421755872.tmp'
13:50:39  00:50:29.529 DEBUG: GET 200 https://sonarqube.company.com/api/plugins/download?plugin=cpp | time=401ms
13:55:50  00:55:46.577 DEBUG: Download plugin 'cobol' to '/home/jenkins/.sonar/_tmp/fileCache13453230483900998320.tmp'
13:55:50  00:55:47.003 DEBUG: GET 200 https://sonarqube.company.com/api/plugins/download?plugin=cobol | time=426ms
13:56:39  00:56:34.846 DEBUG: Download plugin 'cssfamily' to '/home/jenkins/.sonar/_tmp/fileCache1492573590564425402.tmp'
13:56:39  00:56:35.145 DEBUG: GET 200 https://sonarqube.company.com/api/plugins/download?plugin=cssfamily | time=299ms
13:59:35  00:59:31.375 DEBUG: Download plugin 'crowd' to '/home/jenkins/.sonar/_tmp/fileCache11643784711110491606.tmp'
13:59:35  00:59:31.774 DEBUG: GET 200 https://sonarqube.company.com/api/plugins/download?plugin=crowd | time=399ms
14:00:03  01:00:00.369 DEBUG: Download plugin 'flex' to '/home/jenkins/.sonar/_tmp/fileCache13486250058296763746.tmp'
14:00:03  01:00:00.700 DEBUG: GET 200 https://sonarqube.company.com/api/plugins/download?plugin=flex | time=331ms
14:00:06  01:00:05.962 DEBUG: Download plugin 'go' to '/home/jenkins/.sonar/_tmp/fileCache3897888693958410953.tmp'
14:00:06  01:00:06.394 DEBUG: GET 200 https://sonarqube.company.com/api/plugins/download?plugin=go | time=432ms
14:04:17  01:04:10.319 DEBUG: Download plugin 'web' to '/home/jenkins/.sonar/_tmp/fileCache6963780307528070472.tmp'
14:04:17  01:04:10.717 DEBUG: GET 200 https://sonarqube.company.com/api/plugins/download?plugin=web | time=398ms
14:04:23  01:04:23.834 DEBUG: Download plugin 'jacoco' to '/home/jenkins/.sonar/_tmp/fileCache14701765043120418146.tmp'
14:04:26  01:04:25.884 DEBUG: GET 200 https://sonarqube.company.com/api/plugins/download?plugin=jacoco | time=2050ms
14:04:34  01:04:34.059 DEBUG: Download plugin 'java' to '/home/jenkins/.sonar/_tmp/fileCache16409298394821814869.tmp'
14:04:38  01:04:37.628 DEBUG: GET 200 https://sonarqube.company.com/api/plugins/download?plugin=java | time=3568ms
14:10:50  01:10:47.307 INFO: Load/download plugins (done) | time=1339485ms
14:10:50  01:10:47.310 INFO: ------------------------------------------------------------------------
14:10:50  01:10:47.310 INFO: EXECUTION FAILURE
14:10:50  01:10:47.310 INFO: ------------------------------------------------------------------------
14:10:50  01:10:47.311 INFO: Total time: 26:23.376s
14:10:50  01:10:47.324 INFO: Final Memory: 14M/240M
14:10:50  01:10:47.324 INFO: ------------------------------------------------------------------------
14:10:50  01:10:47.324 ERROR: Error during SonarScanner execution
14:10:50  java.lang.IllegalStateException: Fail to download plugin [java] into /home/jenkins/.sonar/_tmp/fileCache16409298394821814869.tmp
14:10:50  	at org.sonar.scanner.bootstrap.PluginFiles.downloadBinaryTo(PluginFiles.java:158)
14:10:50  	at org.sonar.scanner.bootstrap.PluginFiles.download(PluginFiles.java:114)
14:10:50  	at org.sonar.scanner.bootstrap.PluginFiles.get(PluginFiles.java:89)
14:10:50  	at org.sonar.scanner.bootstrap.ScannerPluginInstaller.loadPlugins(ScannerPluginInstaller.java:77)
14:10:50  	at org.sonar.scanner.bootstrap.ScannerPluginInstaller.installRemotes(ScannerPluginInstaller.java:60)
14:10:50  	at org.sonar.scanner.bootstrap.ScannerPluginRepository.start(ScannerPluginRepository.java:62)
14:10:50  	at org.sonar.core.platform.StartableCloseableSafeLifecyleStrategy.start(StartableCloseableSafeLifecyleStrategy.java:40)
14:10:50  	at org.picocontainer.injectors.AbstractInjectionFactory$LifecycleAdapter.start(AbstractInjectionFactory.java:84)
14:10:50  	at org.picocontainer.behaviors.AbstractBehavior.start(AbstractBehavior.java:169)
14:10:50  	at org.picocontainer.behaviors.Stored$RealComponentLifecycle.start(Stored.java:132)
14:10:50  	at org.picocontainer.behaviors.Stored.start(Stored.java:110)
14:10:50  	at org.picocontainer.DefaultPicoContainer.potentiallyStartAdapter(DefaultPicoContainer.java:1016)
14:10:50  	at org.picocontainer.DefaultPicoContainer.startAdapters(DefaultPicoContainer.java:1009)
14:10:50  	at org.picocontainer.DefaultPicoContainer.start(DefaultPicoContainer.java:767)
14:10:50  	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
14:10:50  	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:123)
14:10:50  	at org.sonar.batch.bootstrapper.Batch.doExecute(Batch.java:72)
14:10:50  	at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:66)
14:10:50  	at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
14:10:50  	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
14:10:50  	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
14:10:50  	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
14:10:50  	at java.base/java.lang.reflect.Method.invoke(Unknown Source)
14:10:50  	at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
14:10:50  	at jdk.proxy1/jdk.proxy1.$Proxy0.execute(Unknown Source)
14:10:50  	at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:189)
14:10:50  	at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:138)
14:10:50  	at org.sonarsource.scanner.cli.Main.execute(Main.java:126)
14:10:50  	at org.sonarsource.scanner.cli.Main.execute(Main.java:81)
14:10:50  	at org.sonarsource.scanner.cli.Main.main(Main.java:62)
14:10:50  Caused by: java.io.EOFException
14:10:50  	at okhttp3.internal.http2.Http2Stream$FramingSource.receive$okhttp(Http2Stream.kt:449)
14:10:50  	at okhttp3.internal.http2.Http2Stream.receiveData(Http2Stream.kt:276)
14:10:50  	at okhttp3.internal.http2.Http2Connection$ReaderRunnable.data(Http2Connection.kt:650)
14:10:50  	at okhttp3.internal.http2.Http2Reader.readData(Http2Reader.kt:180)
14:10:50  	at okhttp3.internal.http2.Http2Reader.nextFrame(Http2Reader.kt:119)
14:10:50  	at okhttp3.internal.http2.Http2Connection$ReaderRunnable.invoke(Http2Connection.kt:618)
14:10:50  	at okhttp3.internal.http2.Http2Connection$ReaderRunnable.invoke(Http2Connection.kt:609)
14:10:50  	at okhttp3.internal.concurrent.TaskQueue$execute$1.runOnce(TaskQueue.kt:98)
14:10:50  	at okhttp3.internal.concurrent.TaskRunner.runTask(TaskRunner.kt:116)
14:10:50  	at okhttp3.internal.concurrent.TaskRunner.access$runTask(TaskRunner.kt:42)
14:10:50  	at okhttp3.internal.concurrent.TaskRunner$runnable$1.run(TaskRunner.kt:65)
14:10:50  	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
14:10:50  	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
14:10:50  	at java.base/java.lang.Thread.run(Unknown Source)

I give up. I thought this was going to be relatively simple to get going but every step has either failed or required additional work. How does anyone use this thing?

Hi,

I’m sorry you’re frustrated.

FWIW, that last error indicates an interruption on your network.

 
Ann