Sonarqube webhook's payload doesn't have the execution duration

sonarqube webhook’s payload doesn’t have the execution duration. we need the duration details as part of the payload for analytics/tracking and reporting purposes. Is it possible to add the execution time /duration details?

Welcome :slight_smile:

don’t know what you mean by duration, the analysis time during the build or the background task
of the compute engine on Sonarqube server.

But in general you may expand the payload with additional parameters, see

Gilbert

Thanks Gilbert for the response. sharing the sample response below which doesn’t have the execution time( or the duration of the analysis execution).

{
“serverUrl”: “https://xxxx-sonarqube.xxxx.net”,
“taskId”: “AYje1J6ZakDoxML_tz-I”,
“status”: “SUCCESS”,
“analysedAt”: “2023-06-21T16:40:23+0000”,
“revision”: “f54c64636b76601aa9820e83f3acaf0f3235f5bf”,
“changedAt”: “2023-06-21T16:40:23+0000”,
“project”: {
“key”: “xxxx:proj-key.all”,
“name”: “xxxxx:proj-name.all”,
“url”: “https://xxxx.com/dashboard?id=xxxx%3Adproj-name.all
},
“branch”: {
“name”: “/usr/feature”,
“type”: “BRANCH”,
“isMain”: false,
“url”: “https://xxxx.com/dashboard?id=xxxx%3Adproj-name.all
},
“qualityGate”: {
“name”: “Quality Gate (Default)”,
“status”: “OK”,
“conditions”: [
{
“metric”: “new_reliability_rating”,
“operator”: “GREATER_THAN”,
“status”: “NO_VALUE”,
“errorThreshold”: “1”
},
{
“metric”: “new_maintainability_rating”,
“operator”: “GREATER_THAN”,
“status”: “NO_VALUE”,
“errorThreshold”: “1”
},
{
“metric”: “new_blocker_violations”,
“operator”: “GREATER_THAN”,
“status”: “NO_VALUE”,
“errorThreshold”: “0”
},
{
“metric”: “new_critical_violations”,
“operator”: “GREATER_THAN”,
“status”: “NO_VALUE”,
“errorThreshold”: “0”
},
{
“metric”: “test_success_density”,
“operator”: “LESS_THAN”,
“value”: “100.0”,
“status”: “OK”,
“errorThreshold”: “100”
}
]
},
“properties”: {
“sonar.analysis.detectedscm”: “git”,
“sonar.analysis.detectedci”: “CircleCI”
}
}

We use Jenkins, i don’t know much about Circle CI, but i guess you may use bash.
There are different ways to compute the elapsed time, i.e.

#!/bin/bash

SONAR_START
# sonar analysis ..
echo "Sonarqube analysis duration: $(date -ud "@$(($(date +%s) - $SONAR_START_TIME))" +%T) (HH:MM:SS)"

then set a property, i.e. sonar.analysis.duration

1 Like