Fetcher Background Information#
The fetcher makes a request against the Sonarqube API, gets the the current status of the project quality gates and saves it as a json file to the evidence path.
Environment variables#
- SONARQUBE_HOSTNAME#
The hostname of the Sonarqube server api.
- SONARQUBE_ENDPOINT#
The path on the host leading to the Sonarqube endpoint. Example:
/sonarqube
- SONARQUBE_PORT#
The port number used to to connect with the Sonarqube api.
- SONARQUBE_PROTOCOL#
The protocol used to to connect with the Sonarqube api. Default value: https
- SONARQUBE_PROJECT_KEY#
The project key from the Sonarqube portal. Not the project name, but often very similar.
- SONARQUBE_PROJECT_TOKEN#
The API token generated from the Sonarqube portal.
Example Output#
The SonarQube fetcher creates a file in the evidence path called sonarqube_qg_status.json
. It has the following structure and contains the status of project quality gates:
{
"projectStatus": {
"status": "ERROR",
"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": "ERROR",
"metricKey": "new_coverage",
"comparator": "LT",
"periodIndex": 1,
"errorThreshold": "80",
"actualValue": "0.0"
},
{
"status": "ERROR",
"metricKey": "bugs",
"comparator": "GT",
"errorThreshold": "50",
"actualValue": "153"
}
],
"periods": [
{
"index": 1,
"mode": "PREVIOUS_VERSION",
"date": "2022-04-14T06:29:06+0000"
}
],
"ignoredConditions": false,
"period": { "mode": "PREVIOUS_VERSION", "date": "2022-04-14T06:29:06+0000" }
}
}
Example config#
Below is an example configuration file that runs SonarQube fetcher. The autopilot is configured in lines: 7-17. Required environment variables are read from provided run environment variables or secrets. Then the autopilot is used by the check 1.1 in line 32 which is part of requirement 5.1.
1metadata:
2 version: v1
3header:
4 name: MACMA
5 version: 1.16.0
6autopilots:
7 sonarqube-autopilot:
8 run: |
9 sonarqube-fetcher
10 sonarqube-evaluator
11 env:
12 SONARQUBE_ENDPOINT: ${{ vars.SONARQUBE_ENDPOINT }}
13 SONARQUBE_HOSTNAME: ${{ vars.SONARQUBE_HOSTNAME }}
14 SONARQUBE_PORT: ${{ vars.SONARQUBE_PORT }}
15 SONARQUBE_PROJECT_KEY: ${{ vars.SONARQUBE_PROJECT_KEY }}
16 SONARQUBE_PROJECT_TOKEN: ${{ secrets.SONARQUBE_PROJECT_TOKEN }}
17 SONARQUBE_PROTOCOL: https
18finalize:
19 run: |
20 html-finalizer
21chapters:
22 "1":
23 title: Project management
24 requirements:
25 "5.1":
26 title: The test strategy was defined/adhered to.
27 text: The test strategy was defined/adhered to.
28 checks:
29 "1.1":
30 title: Sonarqube QG Report
31 automation:
32 autopilot: sonarqube-autopilot