Skip to main content

SonarQube

In this example you are going to create a webhook integration between SonarQube's SonarCloud and Port, which will ingest SonarQube code quality analysis entities.

Prerequisitesโ€‹

Create the following blueprint definition and webhook configuration:

SonarQube analysis blueprint
{
"identifier": "sonarCloudAnalysis",
"description": "This blueprint represents a SonarCloud Analysis in our software catalog",
"title": "SonarCloud Analysis",
"icon": "sonarqube",
"schema": {
"properties": {
"serverUrl": {
"type": "string",
"format": "url",
"title": "Server URL"
},
"projectName": {
"type": "string",
"title": "Project name"
},
"projectUrl": {
"type": "string",
"format": "url",
"title": "Project URL"
},
"branchName": {
"type": "string",
"title": "Branch Name"
},
"branchType": {
"type": "string",
"title": "Branch Type"
},
"branchUrl": {
"type": "string",
"format": "url",
"title": "Branch URL"
},
"qualityGateName": {
"type": "string",
"title": "Quality Gate Name"
},
"qualityGateStatus": {
"type": "string",
"title": "Quality Gate Status",
"description": "General status of quality checks"
},
"qualityGateConditions": {
"type": "array",
"items": {
"type": "object"
},
"title": "Quality Gate Conditions",
"description": "Conditions of the qaulity gate"
},
"status": {
"type": "string",
"title": "General Status"
}
},
"required": []
},
"mirrorProperties": {},
"calculationProperties": {},
"relations": {}
}
SonarQube analysis webhook configuration

Remember to replace the WEBHOOK_SECRET with the real secret you specify when creating the webhook in SonarCloud.

{
"identifier": "sonarCloudMapper",
"title": "SonarCloud mapper",
"description": "A webhook configuration to map SonarCloud analysis runs to Port",
"icon": "sonarqube",
"mappings": [
{
"blueprint": "sonarCloudAnalysis",
"entity": {
"identifier": ".body.taskId",
"title": ".body.project.name + \"-\" + .body.taskId",
"properties": {
"serverUrl": ".body.serverUrl",
"status": ".body.status",
"projectName": ".body.project.name",
"projectUrl": ".body.project.url",
"branchName": ".body.branch.name",
"branchType": ".body.branch.type",
"branchUrl": ".body.branch.url",
"qualityGateName": ".body.qualityGate.name",
"qualityGateStatus": ".body.qualityGate.status",
"qualityGateConditions": ".body.qualityGate.conditions"
}
}
}
],
"enabled": true,
"security": {
"secret": "WEBHOOK_SECRET",
"signatureHeaderName": "X-Sonar-Webhook-HMAC-SHA256",
"signatureAlgorithm": "sha256",
"signaturePrefix": ""
}
}

Create the SonarCloud webhookโ€‹

  1. Go to SonarCloud and select a project you want to configure a webhook for;
  2. Click on Administration at the bottom left of the page and select Webhooks;
  3. Click on Create
  4. Input the following details:
    1. Name - use a meaningful name such as Port Webhook;
    2. URL - enter the value of the url key you received after creating the webhook configuration;
    3. Secret - enter the secret value you specified when creating the webhook;
  5. Click Create at the bottom of the page.
tip

In order to view the different payloads and events available in SonarQube webhooks, look here

Done! any new analysis you run (for example, on new PRs or changes to PRs) will trigger a webhook event that SonarCloud will send to the webhook URL provided by Port. Port will parse the events according to the mapping and update the catalog entities accordingly.