How to get values for sonar.branch and sonar.bitbucket.branchName in aws code build?

0

Hi i am using aws code build with sonar for bitbucket pull request decoration… but i am not getting any comments on pull request… aws codebuild logs… [sonar4bitbucket] No open pull requests with source branch ‘’ found. No analysis will be performed. … here is my aws code build command … sonar-scanner -Dsonar.branch=$GIT_BRANCH -Dsonar.bitbucket.branchName=$GIT_BRANCH -Dsonar.analysis.mode=issues -Dsonar.bitbucket.oauthClientSecret=secret -Dsonar.bitbucket.oauthClientKey=key -Dsonar.bitbucket.minSeverity=INFO -Dsonar.host.url=my server-url -Dsonar.bitbucket.teamName=teamname -Dsonar.bitbucket.repoSlug=myreponame -Dsonar.bitbucket.accountName=my-account-name -Dsonar.bitbucket.approvalFeatureEnabled=false -Dsonar.bitbucket.buildStatusEnabled=true i think the problem is with these two properties i,e -Dsonar.branch=$GIT_BRANCH -Dsonar.bitbucket.branchName=$GIT_BRANCH but i dont know how to get the values of these from aws code build environmental variables (https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-env-vars.html)

Hi @Husnain,

Welcome to our community forum.

What version of Bitbucket Server and SonarQube are you using?

Do you have the SonarQube report in your PR like this:

I see some parameters that I don’t know like -Dsonar.bitbucket.oauthClientSecret or -Dsonar.bitbucket.oauthClientKey
Where do they come from ?

May I ask to format a little bit your message next time otherwise it’s quite difficult to read, thanks!

Cheers,

Thanks for quick response :slight_smile: sorry for the format … ok i have found the solution …
with this command

      - curl -fsSL https://raw.githubusercontent.com/thii/aws-codebuild-extras/master/install >> extras.sh
      - . ./extras.sh

and then passing CODEBUILD_GIT_BRANCH variable to Sonar i,e -Dsonar.branch=$CODEBUILD_GIT_BRANCH -Dsonar.bitbucket.branchName=$CODEBUILD_GIT_BRANCH
so sonar will get Pull request source branch and analyze it and decorate pull request …
here is link for further details …


Thanks :slight_smile:

Hi @Husnain,

Thanks for posting the solution! :+1:

Cheers,