1

I want write script as Command Line in TeamCity for break my assembly. I using SonnarQube v: 7.....

My script is:

set PROJECTKEY="%sonar.proj.key%"
set QGSTATUS=`"%curl.exe%" -s -u 
http://SONNAR_URL:9000/api/qualityates/project_status?projectKey=$PROJECTKEY

if "%%QGSTATUS%%" == "OK" exit 0
if "%%QGSTATUS%%" == "ERROR" exit 1

But request

http://SONNAR_URL:9000/api/qualityates/project_status?projectKey=$PROJECTKEY

return for example this message:

 "projectStatus": {
       "status": "ERROR",
       "conditions": [
           {
               "status": "ERROR",
               "metricKey": "new_security_rating",
               "comparator": "GT",
               "periodIndex": 1,
               "errorThreshold": "1",
               "actualValue": "5"
           },
           {
               "status": "ERROR",
               "metricKey": "new_reliability_rating",
               "comparator": "GT",
               "periodIndex": 1,
               "errorThreshold": "1",
               "actualValue": "3"
           },
           {
               "status": "OK",
               "metricKey": "new_maintainability_rating",
               "comparator": "GT",
               "periodIndex": 1,
               "errorThreshold": "1",
               "actualValue": "1"
           },

But I need, that api requst return me only status "Failed" or Error.

It's necessary for break my assembly in TeamCity

Script from hear (Quality Gate Failure in SonarQube does not fail the build in Teamcity)

not working for me, maybe because I using SonnarQube v 7...

How write correct script for TeamCity or how write correct API request, that get one word - Error or Ok

Vasilenko
  • 21
  • 4

1 Answers1

0

I also had this problem and managed to solve with the example below. Hope this helps!

You have to enter this code by creating a PowerShell step in Teamcity.

$QGSTATUS = curl.exe -s -u yourLogin:yourPassword http://YourSonarAPIQualityGate | jq '.projectStatus.status'

if ($QGSTATUS -eq "OK")
{
 echo SUCCESS
 exit 0
}
else 
{
 echo "QUALITY GATE SONAR ERROR"
 exit 1
}
  • But this is script only not working. I see Error: The term 'jq' is not recognized as the name of a cmdlet, function, I use Runner type: "PowerShell" My Script is: set PROJECTKEY="%sonar.proj.key%" $QGSTATUS = %curl.exe% -s -u login:password http://sonarqube.stc:9000/api/qualitygates/project_status?projectKey=$PROJECTKEY | jq '.projectStatus.status' if ($QGSTATUS -eq "OK") { echo SUCCESS exit 0 } else { echo "QUALITY GATE SONAR ERROR" exit 1 } – Vasilenko Aug 29 '19 at 10:22