Webhooks notify external services when a project analysis is complete. An HTTP POST request including a JSON payload is sent to each URL. URLs may be specified at both the project and global levels. Project-level specification does not replace global-level webhooks. All hooks at both levels are called.
The HTTP(S) call:
- is made regardless of the status of the background task
- includes a JSON document as payload, using the POST method
- has a content type of "application/json", with UTF-8 encoding
You can configure up to 10 webhooks in Your Project > Administration > Webhooks.
An additional set of 10 webhooks can be configured at the global level in Your Organization > Administration > Configuration > Webhooks.
If configured, all 20 webhooks will be executed.
The webhook administration console shows the result and timestamp of the most recent delivery of each webhook with the payload available via the list icon. Results and payloads of earlier deliveries are available from the tools menu to the right of each webhook.
Response records are purged after 30 days.
The URL must respond within 10 seconds or the delivery is marked as failed.
An HTTP header "X-SonarQube-Project" with the project key is sent to allow quick identification of the project involved.
The payload is a JSON document that includes:
- when the analysis was performed: see "analysedAt"
- the identification of the project analyzed: see "project"
- each quality gate criterion checked and its status: see "qualityGate"
- the quality gate status of the project: see "qualityGate.status"
- the status and the identifier of the background task : see "status" and "taskId"
- user-specified properties: see "properties"
After you've configured your server to receive payloads, you want to be sure that the payloads you receive are initiated by SonarCloud and not by attackers. You can do this by validating a hash signature that ensures that requests originate from SonarCloud.
To set your secret in SonarCloud:
- From the project or organization where you're securing your webhooks, navigate to the webhooks settings at Administration > Webhooks
- You can either select Create to create a new webhook or click an existing webhook's settings drop-down and select Update.
- Enter a random string in the Secret text box. This is used as the key to generate the HMAC hex digest value in the
- Select Update.
After setting your secret, it's used by SonarCloud to create a hash signature with each payload that's passed using the
X-Sonar-Webhook-HMAC-SHA256 HTTP header. The header value needs to match the signature you are expecting to receive. SonarCloud uses a HMAC lower-case SHA256 digest to compute the signature of the request body. Here's some sample Java code for your server:
If the signatures don't match, then the payload should be ignored.
A basic authentication mechanism is supported by providing user/password in the URL of the Webhook such as
If you provide additional properties to your SonarScanner using the pattern
sonar.analysis.*, these properties will be automatically added to the section "properties" of the payload.
For example these additional parameters:
would add this to the payload: