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.
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.
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?
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).