SonarQube Webhook is sending the previous version of MR id

Hi Everyone,

Im currently using SonarQube Community Build v25.1.0.102122, deployed using Docker

I am running sonar-scanner from my gitlab ci when there is new merge request. Below are my sonar-scanner command that I use.

**sonar-scanner** -X -Dsonar.host.url="${SONAR_HOST_URL}" -Dsonar.projectKey="projec_key_123_456" -Dsonar.python.version=3.11 -Dsonar.projectName="${CI_PROJECT_NAME}:${CI_PROJECT_ID}:${CI_MERGE_REQUEST_IID}" -Dsonar.gitlab.ref_name=${CI_MERGE_REQUEST_IID} -Dsonar.qualitygate.wait=true -Dsonar.qualitygate.timeout=300

This part run with no problem, and the value of CI_MERGE_REQUEST_IID is correct according to the Merge Request that is created. Once this script run, it will trigger the webhook in the SonarQube and it will send the result to the Gitlab MR page as comment, which is also a success.

The problem Im having right now is that, why is the value of CI_MERGE_REQUEST_IID is -1 from its value? For instance if the MR ID when sonar-scanner command is running is 33, the webhook will pass 32 instead of 33.

One more thing to note, the SonarQube webhook received by the GCP Cloud Run, and the GCP Cloud Run will write to the Gitlab’s MR comment. It’s designed this way because our Gitlab instance is behind firewall.

Thanks

Hi,

Welcome to the community!

What project name is created? I would expect it to also be 32 instead of 33. Nothing on the Sonar side is doing that interpolation. SonarQube is just using what was passed in.

 
HTH,
Ann

Hello Ann,

Yes, the project name is correct as I passed from Gitlab, as you can see the project that i pass from gitlab ci is formatted as api:4508:35(project_name:project_id:mr_id), where 35 is the correct MR id.

Below is the command line that i use to run sonar scanner from gitlab-ci

- sonar-scanner -X -Dsonar.host.url="${SONAR_HOST_URL}" -Dsonar.projectKey="project_key_with_random_string" -Dsonar.python.version=3.11 -Dsonar.projectName="${CI_PROJECT_NAME}:${CI_PROJECT_ID}:${CI_MERGE_REQUEST_IID}" -Dsonar.gitlab.ref_name=${CI_MERGE_REQUEST_IID} -Dsonar.qualitygate.wait=true -Dsonar.qualitygate.timeout=300

But when I check the webhook delivery, as you can see it’s sent as 34

Also important to note that, if i run the MR job again it will provide the correct MR id

Please advise.

Hi,

Are you sure that your two screenshots go together? Where does the URL in the payload take you? Is it to project 35 or 34?

I believe you can check the webhook payload that was sent via the UI. Can you double-check api:4508:35’s first webhook payload to verify the project:name in it?

Because by the time webhooks are processed, the analysis context has been discarded, I believe, and SonarQube is reading from the project itself to assemble these values.

 
Ann

Hi Ann,

Yes, the 2 screenshots go together as I only have 1 gitlab ci pipeline for testing at the moment. Just to be clear the number 34/35 will change based on which MR ID provided in the gitlab ci.

After doing some digging on the interweb, i’ve found that i can use the sonar.analysis.[key]=[value] parameters where I can send out custom parameter to the Cloud Run, which produce more consistent output.

Anyway, thanks for your help Ann, appreciate it.

Regards,
Zul Ikmal