PR Decorations are not visible on Bitbucket cloud, despite the reports being sent from sonarqube

Hi,

  • Sonarqube version: Developer Edition Version 9.9 (build 65466)
  • SonarQube Scanner for JenkinsVersion: 2.15
  • SonarQube is self hosted on GCP vm

Tried to integrate sonar for PR analysis as a part of CI step using jenkins and send PR decoration to Bitbucket cloud. We are getting the PR details using bitbucket api as a part of build step.

Script used during build process in Jenkins

echo "Preparing env variables for sonar-scanner"

if [ ! -d ${WORKSPACE}/sonar/${branch} ];
then
mkdir -p ${WORKSPACE}/sonar/${branch}
fi

if [ ! -f ${WORKSPACE}/sonar/${branch}/sonar-scanner.properties ];
then
echo "Creating sonar-scanner.properties file on ${WORKSPACE}/sonar/${branch}"
touch ${WORKSPACE}/sonar/${branch}/sonar-scanner.properties
fi

read var1 var2 var3 < <(echo $(curl --header 'Content-Type: application/json' --silent -u "${bit_bucket_appusername}:${bit_bucket_app_password}" https://api.bitbucket.org/2.0/repositories/financetech/payvoo-common-utils/pullrequests?q=source.branch.name+%3D+%22${branch}%22+AND+state+%3D+%22OPEN%22|jq -r '.[] | .[] | .id, .destination.branch.name, .source.repository.uuid' 2>/dev/null))

pr_id=$var1
pr_base_branch=$var2
pr_repository_uuid=$var3

if [ ! -z "$pr_id" ] && [ ! -z "$pr_base_branch" ];
then
sonar_pr_analysis=$(printf '%s' "sonar.pullrequest.branch=${branch}")$'\n'
sonar_pr_analysis+=$(printf '%s' "sonar.pullrequest.key=$pr_id")$'\n'
sonar_pr_analysis+=$(printf '%s' "sonar.pullrequest.base=$pr_base_branch")$'\n'
#sonar_pr_analysis+=$(printf '%s' "sonar.pullrequest.provider=bitbucketcloud")$'\n'
sonar_pr_analysis+=$(printf '%s' "sonar.pullrequest.bitbucketcloud.owner=financetech")$'\n'
sonar_pr_analysis+=$(printf '%s' "sonar.pullrequest.bitbucketcloud.repository=$pr_repository_uuid")$'\n'
sonar_pr_analysis+=$(printf '%s' "sonar.pullrequest.bitbucketcloud.triggerCommit=fullShaOfTheCommitThatTriggeredTheBuild")$'\n'
echo "$sonar_pr_analysis" > ${WORKSPACE}/sonar/${branch}/sonar-scanner.properties
else
sonar_br_analysis=$(echo "sonar.branch.name=${branch}")
echo "$sonar_br_analysis" > ${WORKSPACE}/sonar/${branch}/sonar-scanner.properties
fi

Sonar-Scanner configuration

sonar.projectKey=common-utils
sonar.login=${Sonar_login}
sonar.sources=/var/lib/jenkins/jobs/temp-payvoo-common-utils/workspace/app
sonar.projectVersion=${BUILD_NUMBER}


sonar.language=java
sonar.coverage.jacoco.xmlReportPaths=${WORKSPACE}/target/scala-2.11/jacoco/report/jacoco.xml
/var/lib/jenkins/jobs/payvoo-notification/workspace/
sonar.java.binaries=.
sonar.host.url=https://sonarqube02.rebase.in

From Sonarqube-server/ce.logs could see the PR decoration are sent successfully but couldn’t able to see the decoration in bitbucket cloud for the relevant PR

Sample ce.log

2023.04.03 06:47:25 DEBUG ce[][o.i.http2.Http2] << 0x00000000     0 SETTINGS      ACK
2023.04.03 06:47:25 DEBUG ce[][o.i.c.TaskRunner] Q10027 starting              : OkHttp api.bitbucket.org applyAndAckSettings
2023.04.03 06:47:25 DEBUG ce[][o.i.c.TaskRunner] Q10029 scheduled after   0 µs: OkHttp api.bitbucket.org onSettings
2023.04.03 06:47:25 DEBUG ce[][o.i.http2.Http2] >> 0x00000000     0 SETTINGS      ACK
2023.04.03 06:47:25 DEBUG ce[][o.i.c.TaskRunner] Q10029 starting              : OkHttp api.bitbucket.org onSettings
2023.04.03 06:47:25 DEBUG ce[][o.i.c.TaskRunner] Q10029 finished run in  41 µs: OkHttp api.bitbucket.org onSettings
2023.04.03 06:47:25 DEBUG ce[][o.i.c.TaskRunner] Q10027 finished run in 464 µs: OkHttp api.bitbucket.org applyAndAckSettings
2023.04.03 06:47:25 DEBUG ce[][o.i.http2.Http2] << 0x00000003   743 HEADERS       END_HEADERS
2023.04.03 06:47:25 DEBUG ce[][o.i.http2.Http2] << 0x00000003   384 DATA          
2023.04.03 06:47:25 DEBUG ce[][o.i.http2.Http2] << 0x00000003     0 DATA          END_STREAM
2023.04.03 06:47:25 DEBUG ce[AYdF3sk6ZlVQaCT9YER0][o.i.c.TaskRunner] Q10005 scheduled after   0 µs: OkHttp ConnectionPool
2023.04.03 06:47:25 DEBUG ce[][o.i.c.TaskRunner] Q10005 starting              : OkHttp ConnectionPool
2023.04.03 06:47:25 DEBUG ce[][o.i.c.TaskRunner] Q10005 run again after 299 s : OkHttp ConnectionPool
2023.04.03 06:47:25 DEBUG ce[][o.i.c.TaskRunner] Q10005 finished run in 107 µs: OkHttp ConnectionPool
2023.04.03 06:47:25 DEBUG ce[AYdF3sk6ZlVQaCT9YER0][c.s.F.D.B.B.E] Commit that triggered PR analysis: 'b6d8eeefdd2e42e4959c846a52b344ba4ec4dab3'
2023.04.03 06:47:25 DEBUG ce[AYdF3sk6ZlVQaCT9YER0][o.i.http2.Http2] >> 0x00000005   117 HEADERS       END_HEADERS
2023.04.03 06:47:25 DEBUG ce[AYdF3sk6ZlVQaCT9YER0][o.i.http2.Http2] >> 0x00000005   279 DATA          END_STREAM
2023.04.03 06:47:26 DEBUG ce[][o.i.http2.Http2] << 0x00000000     4 WINDOW_UPDATE 
2023.04.03 06:47:26 DEBUG ce[][o.i.http2.Http2] << 0x00000005   360 HEADERS       END_HEADERS
2023.04.03 06:47:26 DEBUG ce[][o.i.http2.Http2] << 0x00000005   502 DATA          
2023.04.03 06:47:26 DEBUG ce[][o.i.http2.Http2] << 0x00000005     0 DATA          END_STREAM
2023.04.03 06:47:26 DEBUG ce[AYdF3sk6ZlVQaCT9YER0][o.i.c.TaskRunner] Q10005 scheduled after   0 µs: OkHttp ConnectionPool
2023.04.03 06:47:26 DEBUG ce[][o.i.c.TaskRunner] Q10005 starting              : OkHttp ConnectionPool
2023.04.03 06:47:26 DEBUG ce[][o.i.c.TaskRunner] Q10005 run again after 299 s : OkHttp ConnectionPool
2023.04.03 06:47:26 DEBUG ce[][o.i.c.TaskRunner] Q10005 finished run in 219 µs: OkHttp ConnectionPool
2023.04.03 06:47:26 DEBUG ce[AYdF3sk6ZlVQaCT9YER0][o.i.http2.Http2] >> 0x00000007    96 HEADERS       END_STREAM|END_HEADERS
2023.04.03 06:47:26 DEBUG ce[][o.i.http2.Http2] << 0x00000007   307 HEADERS       END_HEADERS
2023.04.03 06:47:26 DEBUG ce[][o.i.http2.Http2] << 0x00000007     0 DATA          END_STREAM
2023.04.03 06:47:26 DEBUG ce[AYdF3sk6ZlVQaCT9YER0][o.i.c.TaskRunner] Q10005 scheduled after   0 µs: OkHttp ConnectionPool
2023.04.03 06:47:26 DEBUG ce[AYdF3sk6ZlVQaCT9YER0][o.i.http2.Http2] >> 0x00000009   122 HEADERS       END_HEADERS
2023.04.03 06:47:26 DEBUG ce[AYdF3sk6ZlVQaCT9YER0][o.i.http2.Http2] >> 0x00000009   613 DATA          END_STREAM
2023.04.03 06:47:26 DEBUG ce[][o.i.c.TaskRunner] Q10005 starting              : OkHttp ConnectionPool
2023.04.03 06:47:26 DEBUG ce[][o.i.c.TaskRunner] Q10005 run again after 298 s : OkHttp ConnectionPool
2023.04.03 06:47:26 DEBUG ce[][o.i.c.TaskRunner] Q10005 finished run in  92 µs: OkHttp ConnectionPool
2023.04.03 06:47:26 DEBUG ce[][o.i.http2.Http2] << 0x00000000     4 WINDOW_UPDATE 
2023.04.03 06:47:27 DEBUG ce[][o.i.http2.Http2] << 0x00000009   428 HEADERS       END_HEADERS
2023.04.03 06:47:27 DEBUG ce[][o.i.http2.Http2] << 0x00000009   462 DATA          
2023.04.03 06:47:27 DEBUG ce[][o.i.http2.Http2] << 0x00000009     0 DATA          END_STREAM
2023.04.03 06:47:27 DEBUG ce[AYdF3sk6ZlVQaCT9YER0][o.i.c.TaskRunner] Q10005 scheduled after   0 µs: OkHttp ConnectionPool
2023.04.03 06:47:27 DEBUG ce[][o.i.c.TaskRunner] Q10005 starting              : OkHttp ConnectionPool
2023.04.03 06:47:27 DEBUG ce[][o.i.c.TaskRunner] Q10005 run again after 297 s : OkHttp ConnectionPool
2023.04.03 06:47:27 DEBUG ce[][o.i.c.TaskRunner] Q10005 finished run in 182 µs: OkHttp ConnectionPool
**2023.04.03 06:47:27 INFO  ce[AYdF3sk6ZlVQaCT9YER0][o.s.c.t.p.a.p.PostProjectAnalysisTasksExecutor] Pull Request decoration | status=SUCCESS | time=3230ms**
2023.04.03 06:47:27 INFO  ce[AYdF3sk6ZlVQaCT9YER0][o.s.c.t.p.a.p.PostProjectAnalysisTasksExecutor] Report branch Quality Gate status to devops platforms | status=SUCCESS | time=0ms
2023.04.03 06:47:27 DEBUG ce[AYdF3sk6ZlVQaCT9YER0][o.s.c.a.AnnotationConfigApplicationContext] Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@c5f2be4, started on Mon Apr 03 06:47:23 UTC 2023, parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@12db845c
2023.04.03 06:47:27 INFO  ce[AYdF3sk6ZlVQaCT9YER0][o.s.c.t.CeWorkerImpl] Executed task | project=common-utils | type=REPORT | pullRequest=54 | id=AYdF3sk6ZlVQaCT9YER0 | submitter=admin | status=SUCCESS | time=4297ms
2023.04.03 06:47:32 DEBUG ce[][c.z.h.p.HikariPool] HikariPool-1 - keepalive: connection org.postgresql.jdbc.PgConnection@73b1454d is alive
2023.04.03 06:47:34 DEBUG ce[][c.z.h.p.HikariPool] HikariPool-1 - Before cleanup stats (total=10, active=0, idle=10, waiting=0)
2023.04.03 06:47:34 DEBUG ce[][c.z.h.p.HikariPool] HikariPool-1 - After cleanup  stats (total=10, active=0, idle=10, waiting=0)
2023.04.03 06:47:34 DEBUG ce[][c.z.h.p.HikariPool] HikariPool-1 - Fill pool skipped, pool has sufficient level or currently being filled (queueDepth=0).

I tried to go through the open-threads relevant to this topic, could find any help from them. It will be of great help if someone could help me to understand why i am not receiving the PR decorations on the bitbucket cloud?

Hey there.

What is the 1 warning when you click on “Last analysis of this PR had 1 warning”?

Hi Colin,

Thank you for your response. Have attached the screen shot of the warning below.

Warning message:

Dependencies/libraries were not provided for analysis of SOURCE files. The ‘sonar.java.libraries’ property is empty. Verify your configuration, as you might end up with less precise results.

It looks like we changed to a branch rather than the PR. Is it the same on the PR?

Yes it’s the same on PR.

Thanks.

I noticed that in this screenshot:

It says 0 builds. :thinking: That’s where a PR analysis would typically take place. Howa are there 0 builds?