Can I get sonarqube results (exit codes) in terminal?

Must-share information (formatted with Markdown):

  • SonarQube v8.6

  • what are you trying to achieve
    I want to run SonarQube from command line and get exit code if I get errors in code analysis.

  • So if analysis is completely successfull exit code 0

  • if some error was found exit code != 0 is thrown.

  • what have you tried so far to achieve this

I have sonarqube running on docker and am able to run it locally and get:

INFO: CPD Executor 4 files had no CPD blocks
INFO: CPD Executor Calculating CPD for 3 files
INFO: CPD Executor CPD calculation finished (done) | time=11ms
INFO: Analysis report generated in 74ms, dir size=97 KB
INFO: Analysis report compressed in 46ms, zip size=21 KB
INFO: Analysis report uploaded in 34ms
INFO: ANALYSIS SUCCESSFUL, you can browse http://localhost:9000/dashboard?id=foo
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://localhost:9000/api/ce/task?id=example
INFO: Analysis total time: 18.668 s
INFO: ------------------------------------------------------------------------
INFO: EXECUTION SUCCESS
INFO: ------------------------------------------------------------------------
INFO: Total time: 19.616s
INFO: Final Memory: 12M/50M
INFO: ------------------------------------------------------------------------
[11:10:42] Analysis finished.

Hi,

Welcome to the community!

It’s useful to distinguish here between:

  • successful analysis (it got to the end and submitted the analysis report to the server
  • passing the Quality Gate (new issues may have been raised, but the code is still releasable)

I suspect what you want relates to a failing Quality Gate rather than an analysis error. We have integrations available for reflecting your Quality Gate status back into your build pipeline, altho the details of that vary by CI flavor.

 
HTH,
Ann

@ganncamp thanks!

is it possible to listen or react from terminal to the event/hook when Quality Gate passes or fails. Or this is only available for CI pipelines providers such as Jenkins and Gitlab-ci?

There is the Build Breaker plugin, which you can install through the Marketplace. We recommend against using it, but it’s available.

 
Ann

@ganncamp is quality gate available for community edition, it is not clear to me in the documentation.

Hi,

Yes, Quality Gating is a core feature. In fact, you should be seeing the default Quality Gate applied to your projects already. (SonarQube admins have the ability to create additional QGs).

 
HTH,
Ann

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.