How to manage empty JSON files?

Hello,

My project is in C++.
I use Sonar Scanner 7.1.0.4889 and Build Wrapper 6.66.

When running a scan on a project which hasn’t been modified since last scan, I get an empty JSON. You’ll tell me: expected behavior.

I run the scanner from Jenkins with a Powershell command:

powershell( script: sonarCommand, returnStdout: true )

sonarCommand is the command line to send to Powershell.

If the command returns a nonzero status code, Jenkins returns an exception. It is dirty…
I’d like to know what is the return value when the Sonar scanner doesn’t see any difference, and so produces an empty JSON. I don’t succeed to find this value in the documentation.

Also, would it possible to not even try to run the scanner, by asking to SonarQube Cloud what was the commit used for the last analysis, and what was the analysis status ? What is the good practice ?

Hi,

What JSON file are we talking about?

 
Thx,
Ann

Hello,

The one leading to this error message when it is empty :slight_smile:

WARN: Unable to locate 'report-task.txt' in the workspace. Did the SonarScanner succeed?
By “empty”, I mean with it points to no differences since lasts scan.

Hi,

Could I have the full analysis log?

 
Ann

Just sent as private message.

Not due to empty JSON, apparently…

Hi,

Yes… I was confused by your assertion that the problem was that the project hadn’t been modified since the last scan.

In fact, your log shows analysis ending successfully.

It also shows that this is a PR analysis, and PR analysis will always look at all the changes in the underlying branch, whether or not you’ve already analyzed them before.

Best practice is to have your pipeline notice that there has been a change and fire automatically based on that.

Why? Instead of invoking PoweShell to invoke the scanner… why not just invoke the scanner directly?

 
Ann

Hello,

By using the Sonar API to ask the SHA1 for the last scan, and comparing it with the SHA1 we plan to scan ?

Well… Anyway, in Jenkins, we have to use the bat or the powershell commands. They’re same. We just have to add an ampersand with the powershell command.
But maybe I musunderstood what you mean.

Hi,

No. By picking up a notification from your SCM.

No, you understood. I was misremembering. Sorry for the confusion.

 
Ann

Hi,

I don’t understand. A notification of which event (my SCM is Git) ? When ?

When I want to launch the run #N of a job Jenkins, for a given Git SHA1, I need to know if a Snar scan has already be done for this SHA1. In my job Jenkins, I do know what is the SHA1 for the processed branch, but I don’t know the SHA1 used for the previous scan.

Hi,

Standard practice is not to choose, episodically, to run the pipeline for a given commit, but to run it automatically on every commit.

Search for something like “run Jenkins pipeline automatically on SCM change” and you should find a wealth of advice on this.

 
HTH,
Ann