SonarScanner failing to run without a clear error

We’ve installed SonarQube 7.9 and we’re able to access it, however scans fail with:

WARN: Unable to locate 'report-task.txt' in the workspace. Did the SonarScanner succeeded?

What am I missing here??

In Jenkins configuration we have set:

  • Name: myqube
  • Server: http://9.46.xxx.yy:9000/
  • Server authentication token: a credential (“mycredential”) pointing to the generated value from Administrator > My account > Security > Generate token
  • Webhook Secret: nothing was selected for this property (in case this matters)

In the Jenkinsfile:

stage ("SonarQube analysis") {
    environment {
        SQ_HOST_URL = "http://9.46.xxx.yyy:9000/"
        SQ_AUTHENTICATION_TOKEN = credentials("mycredential")
        SQ_PROJECT_KEY = "myvalue"
    }

    steps {
        script {    
            withSonarQubeEnv('myqube') {
                sh "sonar-scanner"
            }
        }
    }
}

stage ("Check for code coverage") {
    steps {
        script {
            qualitygate = waitForQualityGate()
            if (qualitygate.status != "OK") {
                currentBuild.result = "FAILURE"
            }
        }
    }
}

In sonar-scanner.properties:

#Configure here general information about the environment, such as SonarQube DB details for example
#No information about specific project should appear here

#----- Default SonarQube server
sonar.host.url=http://9.46.xxx.yyy:9000/

#----- Default source code encoding
#sonar.sourceEncoding=UTF-8

In SonarQube:

Hi,

i guess it’s an initial analysis and you hit this, see thread for two possible workarounds =
https://community.sonarsource.com/t/clarify-the-use-of-sonar-branch-name/18872

Gilbert

I tried changing sonar-scanner to sonar-scanner ${branch != 'master' ? "-Dsonar.branch.name=${branch}" : ''} but it didn’t seem to make a difference. Still complaining that it can’t find report-task.txt…

What’s weird is that the same code works for one repository but fails for another, but I cannot find any configuration difference between them…

@Julien_HENRY @NicoB

Can you please help me here?
The difference between the working and not-working analysis is that:

  • In the working one, it’s a repository that its main branch is the develop branch
  • In the not-working one, it’s a repository that its main branch is the master branch

For both repositories this was their first-ever run and they did not have a project in SonarQube.
How do I resolve this? We cannot yet upgrade to v8 and we cannot create a develop branch.

Please provide all Sonarqube relevant parts of the Jenkins console log.
Did you check the Sonarqube logs for further details ?

Thanks for replying, Gilbert.

How do I check the SonarQube logs for this failure?
It is the sonar scanner that is failing to run in this case, no?

The Jenkins log only provides the following:

[Pipeline] { (SonarQube analysis)
[Pipeline] withCredentials
Masking supported pattern matches of $SQ_AUTHENTICATION_TOKEN
[Pipeline] {
[Pipeline] withEnv
[Pipeline] {
[Pipeline] script
[Pipeline] {
[Pipeline] withSonarQubeEnv
Injecting SonarQube environment variables using the configuration: certificate-manager
[Pipeline] {
[Pipeline] }
WARN: Unable to locate 'report-task.txt' in the workspace. Did the SonarScanner succeeded?
[Pipeline] // withSonarQubeEnv
[Pipeline] }
[Pipeline] // script
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // withCredentials
[Pipeline] }
[Pipeline] // stage

And as mentioned the exact same pipeline for a different repository that its default branch is develop rather than master, works.

Hi,

what is your scanner version ?
i’ve asked because the ‘unable to locate report-task.txt’ appears for different errors, but we need
to find the root cause.
So, there are no more Sonarqube related entries in the Jenkins console log ?
Please adjust the loglevel for the scanner like that
sh "sonar-scanner -X" to get more output.

To go further we need to check the Sonarqube server logs located in
$SONARQUBE_HOME/logs for related entries, e.g. when using permission templates and the projektkey matches multiple permission templates it is seen in web.log

It’s also recommended to create a log recorder for Sonarqube in Jenkins via

But it seems a similar problem with the initial scan as descibed in the mentioned thread.
This problem with the initial scan and the use of sonar.branch.name is fixed in version 8.
i’ve created a shared library in Jenkins that checks via Sonarqube web api if the project exists and if not creates it, as we’re still bound to version 7.9.x
After all you can create the Sonarqube project manually.

After all you can create the Sonarqube project manually.

I’ve created it manually and ran both sonar-scanner and sonar-scanner ${branch != 'master' ? "-Dsonar.branch.name=${branch}" : ''} with the same error.

The sonar-scanner version is 3.3.0.1492

The -X parameter didn’t bring up more details ?
3.3.0.1492 is rather old, please try with the latest version of Sonar Scanner and Sonar Jenkins plugin
https://docs.sonarqube.org/latest/analysis/scan/sonarscanner-for-jenkins/
https://docs.sonarqube.org/latest/analysis/scan/sonarscanner/

Also there must be more output in Jenkins console, as e.g. the projectkey … etc. also without -X

The -X parameter didn’t bring up more details ?

Nope. Same error is displayed.

Sonarscanner for Jenkins

It is using the latest version.

Sonarscanner

I will try updating the version.

Did you also check the Sonarqube server logs ?
access.log, web.log, sonar.log …

I do not have access to those myself. If no luck with the updated sonar-scanner I will request for the latest logs.

No change using the latest sonar scanner.

Remove the .txt extension to open as zip.
logs.zip.txt (126.1 KB)

There are some unexplained errors there…

@IdanAdar can you post the full logs of the scan as well? Not just the single warning received. Something else may be the true error causing failure.

  38 passing (34s)


=============================== Coverage summary ===============================
Statements   : 91.91% ( 216/235 )
Branches     : 86.36% ( 152/176 )
Functions    : 100% ( 34/34 )
Lines        : 93.21% ( 206/221 )
================================================================================
[Pipeline] junit
Recording test results
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Java Unit tests)
Stage "Java Unit tests" skipped due to when conditional
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (SonarQube analysis)
[Pipeline] withCredentials
Masking supported pattern matches of $SQ_AUTHENTICATION_TOKEN
[Pipeline] {
[Pipeline] withEnv
[Pipeline] {
[Pipeline] script
[Pipeline] {
[Pipeline] withSonarQubeEnv
Injecting SonarQube environment variables using the configuration: certificate-manager
[Pipeline] {
[Pipeline] }
WARN: Unable to locate 'report-task.txt' in the workspace. Did the SonarScanner succeeded?
[Pipeline] // withSonarQubeEnv
[Pipeline] }
[Pipeline] // script
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // withCredentials
[Pipeline] }
[Pipeline] // stage

We’ve updated now to 8.2.0.32929 but the same error continues.

I did another test - I added sonar-scanner -v and it failed too. But then I also added sonar-scanner -v at an earlier stage and it does work…

It’s confusing that your jenkins console log has not more entries - even with using -X = loglevel debug !?
Already with normal loglevel and regardless of the scanner (cli, maven …) there should be entries like
that, e.g. a Jenkins console log of a windows node using the cli scanner:

[Pipeline] withSonarQubeEnv
Injecting SonarQube environment variables using the configuration: SONARFOO
[Pipeline] {
[Pipeline] bat

E:\Jenkins\workspace\foo-bar_master-H3VR45APWDZ47PTGKRBPLPNELBVOJBC245QGTEGBWFHRWCHIZASQ>E:\Jenkins\tools\hudson.plugins.sonar.SonarRunnerInstallation\SonarQube_Scanner_4.0.0\sonar-scanner-4.0.0.1744/bin/sonar-scanner
INFO: Scanner configuration file: E:\Jenkins\tools\hudson.plugins.sonar.SonarRunnerInstallation\SonarQube_Scanner_4.0.0\sonar-scanner-4.0.0.1744\bin..\conf\sonar-scanner.properties
INFO: Project root configuration file: E:\Jenkins\workspace\foo-bar-H3VR45APWDZ47PTGKRBPLPNELBVOJBC245QGTEGBWFHRWCHIZASQ\sonar-project.properties
INFO: SonarQube Scanner 4.0.0.1744
INFO: Java 1.8.0_60 Oracle Corporation (64-bit)
INFO: Windows NT (unknown) 10.0 amd64
INFO: User cache: E:\UserHome\sonar\cache
INFO: SonarQube server 7.9.1
INFO: Default locale: “de_DE”, source code encoding: “UTF-8”
WARN: SonarScanner will require Java 11+ to run starting in SonarQube 8.x
INFO: Load global settings
INFO: Load global settings (done) | time=182ms
INFO: Server id: xxx-xxx
INFO: User cache: E:\UserHome\sonar\cache
INFO: Load/download plugins
INFO: Load plugins index
INFO: Load plugins index (done) | time=51ms
INFO: Load/download plugins (done) | time=174ms
INFO: Loaded core extensions: developer-scanner
INFO: Process project properties
INFO: Execute project builders
INFO: Execute project builders (done) | time=3ms
INFO: Project key: com.foo.bar:foo-bar
INFO: Base dir: E:\Jenkins\workspace\foo-bar_master-H3VR45APWDZ47PTGKRBPLPNELBVOJBC245QGTEGBWFHRWCHIZASQ
INFO: Working dir: E:\Jenkins\workspace\foo-bar_master-H3VR45APWDZ47PTGKRBPLPNELBVOJBC245QGTEGBWFHRWCHIZASQ.scannerwork
INFO: Load project settings for component key: ‘com.foo.bar:foo-bar’
INFO: Load project settings for component key: ‘com.foo.bar:foo-bar’ (done) | time=31ms
[…]

Checking your provided Sonarqube server logs:
the access.log has only successful submits with http 200 for different projectKeys
only the web.log has one exception

2020.04.23 06:32:19> INFO web[o.a.c.h.Http11Processor] Error parsing HTTP request header
Note: further occurrences of HTTP header parsing errors will be logged at DEBUG level.
java.lang.IllegalArgumentException: Invalid character found in method name. HTTP method names must be tokens

Never had seen this, searching the web indicates that is because

This exception can occur when you try to execute HTTPS request from client on endpoint which isn’t HTTPS enabled. Client will encrypt request data when server is expecting raw data.

Didn’t find any other suspicious entries in the logs.
Just guessing = maybe the one job failing runs on another jenkins node that’s
not configured correctly, http ↔ https !?

Did the Jenkins logrecorder reveal something ?
Maybe you can provide the sonar-project.property file of both projects = works / works not ?