User Tools

Site Tools


devops:sonarqube

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
devops:sonarqube [2023/11/01 07:15] – removed - external edit (Unknown date) 127.0.0.1devops:sonarqube [2023/11/01 07:15] (current) – ↷ Page moved from camunda:devops:sonarqube to devops:sonarqube skipidar
Line 1: Line 1:
 +===== Sonarqube =====
  
 +The sonarqube is the static code analysis tool.
 +
 +
 +=== Jenkins ===
 +
 +
 +
 +== Scan==
 +
 +=== In Jenkins ===
 +To scan the code use the Jenkins plugin "SonarQube Scanner"
 +
 +=== via console ===
 +https://techexpert.tips/sonarqube/sonarqube-scanner-installation-ubuntu-linux/
 +
 +
 +== Break build==
 +
 +To break the build, when the sonarqube-project "workspaceteam1-project1team1" is red - one could use the following script:
 +
 +<code>
 +#!/bin/bash                                                                                                                                                                                     
 +CURL='/usr/bin/curl'
 +RVMHTTP="http://sonar:9000/sonar/api/qualitygates/project_status?projectKey=workspaceteam1-project1team1"
 +CURLARGS="-u adop:123abc123"
 +
 +# you can store the result in a variable
 +raw="$($CURL $CURLARGS $RVMHTTP)"
 +
 +if [[ $raw = *"\"status\":\"ERROR\""* ]]; then
 +  exit 1
 +else
 +  exit 0
 +fi 
 +</code>
 +
 +Here we can retrieve the project key by using the following api:
 +<code>
 +curl -u adop:123abc123 http://52.210.126.173/sonar/api/projects/index?search="team1"
 +
 +
 +[{"id":"1","k":"workspaceteam1-project1team1","nm":"WorkspaceTeam1/Project1Team1","sc":"PRJ","qu":"TRK"}]
 +</code>
 +
 +The next step is the request of the project state
 +<code>
 +curl -u adop:123abc123 http://52.210.126.173/sonar/api/qualitygates/project_status?projectKey=workspaceteam1-project1team1
 +
 +
 +{  
 +   "projectStatus":{  
 +      "status":"ERROR",
 +      "conditions":[  
 +         {  
 +            "status":"OK",
 +            "metricKey":"new_vulnerabilities",
 +            "comparator":"GT",
 +            "periodIndex":1,
 +            "errorThreshold":"0",
 +            "actualValue":"0"
 +         },
 +         {  
 +            "status":"OK",
 +            "metricKey":"new_bugs",
 +            "comparator":"GT",
 +            "periodIndex":1,
 +            "errorThreshold":"0",
 +            "actualValue":"0"
 +         },
 +         {  
 +            "status":"OK",
 +            "metricKey":"new_sqale_debt_ratio",
 +            "comparator":"GT",
 +            "periodIndex":1,
 +            "errorThreshold":"1",
 +            "actualValue":"0.0"
 +         },
 +         {  
 +            "status":"ERROR",
 +            "metricKey":"bugs",
 +            "comparator":"NE",
 +            "errorThreshold":"0",
 +            "actualValue":"1"
 +         }
 +      ],
 +      "periods":[  
 +         {  
 +            "index":1,
 +            "mode":"previous_version",
 +            "date":"2018-05-09T14:19:38+0000"
 +         },
 +         {  
 +            "index":2,
 +            "mode":"previous_analysis",
 +            "date":"2018-05-10T09:38:00+0000",
 +            "parameter":"2018-05-10"
 +         },
 +         {  
 +            "index":3,
 +            "mode":"days",
 +            "date":"2018-05-09T14:19:38+0000",
 +            "parameter":"30"
 +         }
 +      ]
 +   }
 +}
 +</code>