Qualitygate api results are inconsistent

Template for a good new topic, formatted with Markdown:

  • ALM used (GitHub, Bitbucket Cloud, Azure DevOps)
    GitHub
  • CI system used (Bitbucket Cloud, Azure DevOps, Travis CI, Circle CI
    AWS CodeBuild and CodePipeline
  • Scanner command used when applicable (private details masked)
    /sonar-scanner-3.3.0.1492-linux/bin/sonar-scanner -Dsonar.login=$LOGIN -Dsonar.host.url=$HOST -Dsonar.projectKey=$Project -Dsonar.organization=$Organization -Dsonar.branch.name=$Branch
  • Languages of the repository
    Python
  • Only if the SonarCloud project is public, the URL
    • And if you need help with pull request decoration, then the URL to the PR too
      project is private
  • Error observed (wrap logs/code around with triple quotes ``` for proper formatting)

I am invoking a branch scan via CLI which appears to work fine. Then I need to curl to retrieve qualitygate status to determine if build should continue.

https://sonarcloud.io/api/qualitygates/project_status?projectKey=XYZ&branch=dev
When using my local machine (cookies, JWT, etc) I get a full response as follows:

status: "OK",
conditions: [
{
status: "OK",
metricKey: "new_reliability_rating",
comparator: "GT",
periodIndex: 1,
errorThreshold: "1",
actualValue: "1"
},
{
status: "OK",
metricKey: "new_security_rating",
comparator: "GT",
periodIndex: 1,
errorThreshold: "1",
actualValue: "1"
},
{
status: "OK",
metricKey: "new_maintainability_rating",
comparator: "GT",
periodIndex: 1,
errorThreshold: "1",
actualValue: "1"
}
],
periods: [
{
index: 1,
mode: "days",
date: "2020-03-12T22:45:54+0100",
parameter: "30"
}
],
ignoredConditions: false
}
}

When using curl with the token I only ever get:

{"projectStatus":{"status":"OK","conditions":[],"periods":[],"ignoredConditions":false}}

curl example:

curl -u <token>: -o foo.json https://sonarcloud.io/api/qualitygates/project_status?projectKey=xyz&branch=dev

I am killing myself to try and get this working correctly from the pipeline (curl). Any ideas?

Welcome to the community!

To get the detailed response, you must use analysisId parameter instead of projectKey and branch. You can get analysisId from the output of /api/ce/task?id=:ceTaskId, and you can get ceTaskId from the scanner output (or rather, the report-task.txt file generated during analysis).

Let me know if this answers your question, or if you need more help!