Hi all,
I try to ex-/import quality gate conditions from multiple instances to a single instance. Therefore I have to rely on a central configuration as code source for our new sonarqube infrastructure.
However… testing a bit with sonarqube’s API I got some question marks. Some have been already been answered, but I need some more clarification on that.
I am no developer and thus have a hard time understanding coding related doc’s: MetricDefinitions
I also have a hard time finding a way to safely remove the right condition based on the ID, I have to filter out by myself…
Given one of my qualitygates from an old sonarqube server instance:
"id": "AWqRA4567xPW4pTcJQrb",
"name": "Java Related",
"conditions": [
{
"id": "AYmr4TXA_R_dyf0mP-ZE",
"metric": "new_security_rating",
"op": "GT",
"error": "1"
},
{
"id": "AYmr4TXA_R_dyf0mP-ZF",
"metric": "new_reliability_rating",
"op": "GT",
"error": "1"
},
{
"id": "AYmr4TXA_R_dyf0mP-ZG",
"metric": "new_maintainability_rating",
"op": "GT",
"error": "1"
},
{
"id": "AYmr4TXA_R_dyf0mP-ZD",
"metric": "security_rating",
"op": "GT",
"error": "4"
},
{
"id": "AYmr4TXA_R_dyf0mP-Y2",
"metric": "coverage",
"op": "LT",
"error": "10"
},
{
"id": "AYmr4TXA_R_dyf0mP-Y7",
"metric": "duplicated_lines_density",
"op": "GT",
"error": "5"
},
{
"id": "AYmr4TXA_R_dyf0mP-Y8",
"metric": "reliability_rating",
"op": "GT",
"error": "4"
I use these conditions and create a dict for my ansible playbook.
I used the metric names that are shown in the UI. I think when I add ‘new_’ to these conditions, they might get double prefixed.
- qualitygate_name: Java Related
operatoren:
- metric: security_rating
operator: GT
error: 1
state: present
- metric: reliability_rating
operator: GT
error: 1
state: present
- metric: maintainability_rating
operator: GT
error: 1
state: present
- metric: security_rating
operator: GT
error: 4
state: present
- metric: coverage
operator: LT
error: 10
state: present
- metric: duplicated_lines_density
operator: GT
error: 5
state: present
- metric: reliability_rating
operator: GT
error: 4
state: present
With that list, I create my quality gate and conditions and receive that:
"msg": [
{
"error": "1",
"id": "AZQX1yyeOyQ12MM6ybmX",
"metric": "new_security_rating",
"op": "GT"
},
{
"error": "1",
"id": "AZQX1yyjOyQ12MM6ybmY",
"metric": "new_reliability_rating",
"op": "GT"
},
{
"error": "1",
"id": "AZQX1yylOyQ12MM6ybmZ",
"metric": "new_maintainability_rating",
"op": "GT"
},
{
"error": "80",
"id": "AZQX1yyoOyQ12MM6ybma",
"metric": "new_coverage",
"op": "LT"
},
{
"error": "3",
"id": "AZQX1yyvOyQ12MM6ybmb",
"metric": "new_duplicated_lines_density",
"op": "GT"
},
{
"error": "100",
"id": "AZQX1yyxOyQ12MM6ybmc",
"metric": "new_security_hotspots_reviewed",
"op": "LT"
}
]
}