Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.6k views
in Technique[技术] by (71.8m points)

is it possible to get sonarqube 8.6 exitcode from terminal based on analysis results?

Hi all I'm on linux and want to run sonarqube locally and based on the analysis result get exit code

  • So for example if 0 errors in code analysis then exit code 0
  • If it has 1 or more error in code analysis then exit code != 0

I run SQ server from docker-compose like this:

version: "3"
services:
  sonarqube:
    container_name: sonarqube
    image: sonarqube:latest
    ports:
      - "9000:9000"
      - "9092:9092"

and then with node I run sonarqube-scanner:

const sonarqubeScanner = require('sonarqube-scanner');
sonarqubeScanner({
    serverUrl: 'http://localhost:9000',
    options : {
        'sonar.sources': '.',
        'sonar.inclusions' : 'src/**',
    }
}, () => {});

Finally I get success on console but no exit codes:

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=foobar
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.
question from:https://stackoverflow.com/questions/65832029/is-it-possible-to-get-sonarqube-8-6-exitcode-from-terminal-based-on-analysis-res

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

It isn't practical for the sonar-scanner to return the scan results, because there are many details that a client might want to see. At the completion of the scan in the sonarqube server, a background task is run that produces the basic statistics based on the guidelines in the quality gate set in the project.

Typically, the SonarQube project has a "Webhook" value that specifies a url to post the background task results to, and that url is usually in Jenkins.

In a Jenkins scripted pipeline job, the "waitForQualityGate()" pipeline step is used to wait for that webhook call to be received.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...