Sonarscanner : Get Passed or Failed QualityGate

Hi

I am executing sonarcloud in my react App . I run ‘node sonarproject.js’ see the contents of sonarproject.js below. This works perfectly well. I see the results in sonarcloud! However, I would like to know if it passed / failed the quality gate. How do I programatically get thing information out??

const sonarqubeScanner = require(“sonarqube-scanner”);

const { BRANCH_NAME } = process.env;

sonarqubeScanner(
{
serverUrl: “https://sonarcloud.io”,
token: “mytoken”,
options: {
“sonar.projectName”: “fun”,
“sonar.projectKey”: “funny”,
“sonar.projectBaseDir”: “…/.”,
“sonar.tests”: “./app/src”,
“sonar.test.inclusions”: “app/src/**/test.tsx”,
“sonar.typescript.lcov.reportPaths”: “app/coverage/lcov.info”,
“sonar.language”: “ts”,
“sonar.sourceEncoding”: “UTF-8”,
“sonar.organization”: “fun”,
“sonar.branch.name”: BRANCH_NAME,
“sonar.branch.target”: “master”,
“Dsonar.scm.provide”: “git”,
},
},
() => process.exit()

Hi,

I think the Measures WebAPI can do what you want: https://sonarcloud.io/web_api/api/measures/component
with parameters component=yourProjectKey and metricKeys=alert_status.

HTH
Claire

What should the authentication be using the API Token ( generated from User → Security)
curl --location --request GET 'https://sonarcloud.io/api/measures/component?component=myprojectKey&metricKeys=alert_status&branch=myBranchName

I tried with Base64 of the API Token as well adding it in raw -u APIToken:

I get the following error

{
“errors”: [
{
“msg”: “Insufficient privileges”
}
]
}

Using cURL, the token can be passed as copied from the generator page, with the -u parameter and a colon after :

curl -u thetoken: --request GET 'https://sonarcloud.io/api/measures/component?component=myprojectKey&metricKeys=alert_status&branch=myBranchName'

If you still hit the “Insufficient privileges” error, please make sure the token has been generated by a valid account that has the “Browse” permission on the project.

Thank you, I am all clear - this is the key. Would really help if sonarcloud publishes a Postman collection

curl -u thetoken: --request GET 'https://sonarcloud.io/api/measures/component?component=myprojectKey&metricKeys=alert_status&branch=myBranchName'
1 Like

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