SonarScanner into multiple jobs declaration in CI

Hi,

I would like to better understand under the hood of the dotnet sonarscanner tool

I know there are many remarks about running the build and tests tasks inside the same job on a CI and that’s the way it works.

For what I understand, the sonarscanner begin and end will get all the report output and send it to the server for analysis.

So I was asking myself, would it possible to send part of data per job in a CI ?

What I am saying is, for a gitlab CI example, we could have something like :

init:
  stage: .pre
  script:
    - dotnet sonarscanner begin /step:true /id:$CI_COMMIT_SHORT_SHA

build:
  stage: build
  script:
    - dotnet sonarscanner beginstep /id:$CI_COMMIT_SHORT_SHA
    - dotnet build
    - dotnet sonarscanner endstep /id:$CI_COMMIT_SHORT_SHA

test:
  stage: test
  script:
    - dotnet sonarscanner beginstep /id:$CI_COMMIT_SHORT_SHA
    - dotnet test
    - dotnet sonarscanner endstep /id:$CI_COMMIT_SHORT_SHA

cleanup:
  stage: .post
  script:
    - dotnet sonarscanner end /id:$CI_COMMIT_SHORT_SHA

In this case, we could keep separated job for each task and avoid an unique sonar task that do everything (and take time)

I am not saying this is a solution, and surely there are a lot of scenario to resolve and it would be a long-term implementation.

I just want to know if hypothetically this could be possible

Thanks.

PS: I was sure this feature was already asked, but didn’t find it

Hi,

I’m not sure I understand what you’re asking. I guess you want to isolate build from test, each with its own begin and end? If that’s what you’re after, I wouldn’t recommend it. begin essentially sets up a listening context, and causes the rules to be run as part of / during the build. The end step wraps up analysis and submits the analysis report to the server.

Run two different begin / end combinations on the same project and you’ll get two different half-analyses that continually overwrite each other because analysis is not additive. It all has to be part of the same analysis.

 
HTH,
Ann

Hi,

Thanks for your answer.

It was not thinking about pure isolation, sorry for my english. For me, the scanner begin and the scanner end actions are at the pipeline level

A block like beginstep and endstep are temporary listening/rules/analysis/… running during a job.

When all the jobs are done, the server would be able to “concat” the different reports and do a final one

For my better personal understanding, how does the scanner listen those 2 tasks below ?

test:
  stage: test
  script:
    - dotnet sonarscanner begin
    - dotnet build
    - dotnet test
    - dotnet sonarscanner end

Does it get all the output in one step ? The scanner does not see any difference between one line, two or three lines ?

Or does it parse the first command output dotnet build, then do internal things, and then parse the dotnet test output, finalize, and send all to the server ?

Hi,

Again, the concatenation happens during the scanner run, not server-side. If you send multiple reports to the server, it won’t concatenate them; it will replace them.

You’re asking for the low-level, technical details? There’s a hint the the docs I linked. Did you check them?

To be honest, I’m not sure what changes are made to the test step. I suspect it’s just an order-of-operations requirement that puts the test step where it is in the sequence.

 
HTH,
Ann

If you send multiple reports to the server, it won’t concatenate them; it will replace them.

That was the initial question. In theory could it be possible to concatenate instead of replace ?

That was all the idea behind the concept of beginstep and endstep. In theory, set a series of functions server-side that add data and not replace them. Then tell the server “ok no more data”, then the server digest everything and “voilà”! (again, just in theory, I can imagine the amount of work, of questions, problems, …)

Through the link you provided I read about the end command:

It […], collects the analysis data generated by the build, the test results, and the code coverage, and then uploads everything to SonarQube Server.

So I assume the scanner does separate task for each dotnetcommand ?

Sorry, this is going off-topic of a simple “suggest feature” :sweat_smile:

Hi,

No.

Okay, in theory if we totally re-engineered everything about how analysis works, then sure. :sweat_smile:

Again, all the concatenation is done CI-side.

 
Ann

Ha, I thought parts were more isolate

But that was really instructive.

Thank you :+1: