# SonarCloud + Bitbucket Cloud pull request & Branches analyse

**URL:** <https://community.sonarsource.com/t/sonarcloud-bitbucket-cloud-pull-request-branches-analyse/41645>\
**Category:** SonarQube Cloud\
**Tags:** bitbucketcloud, branches, pull-request, sonarqube-cloud\
**Created:** [April 14, 2021, 12:56pm UTC](https://community.sonarsource.com/t/sonarcloud-bitbucket-cloud-pull-request-branches-analyse/41645 "2021-04-14T12:56:40Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![tahacanatak](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/tahacanatak/32/21220_2.png) [@tahacanatak](https://community.sonarsource.com/u/tahacanatak)\
**Post date:** [April 14, 2021, 12:56pm UTC](https://community.sonarsource.com/t/sonarcloud-bitbucket-cloud-pull-request-branches-analyse/41645/1 "2021-04-14T12:56:40Z")

</div>

Hi,  
I’m having a few problems while scanning pull requests coming to a private project in bitbucket cloud.

the transactions I have done so far;

- I integrated my project in bitbucket cloud into sonar cloud.
- I use aws codebuild as a trigger. When a pull request is create, the codebuild runs and analyzes the incoming pull request.I can see the analysis as “passed” on the sonarcloud screen.

**my problems**

1 ) I cannot view my branches and pull requests in the repo. So I cannot distinguish which analysis result belongs to which pull request.

 ![sonar](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/3X/9/5/95c3a4f4687925a78faa0f3e608124f1dcc4b2fa.png)

2 ) I cannot see the results of the analyzed pull request on the bitbucket cloud pull request screen.

 ![pr](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/3X/c/2/c201d2ea281179c1209967ff62f53dfebaed0594.png)

* * *

this image is codebuild webhook configurations

 ![webhook](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/3X/c/0/c002aa3d77c9a617ef672b99bb345ec4c6dad394.png)

**this is my buildspec.yml file**

version: 0.2

phases:  
install:  
runtime-versions:  
nodejs: 12  
java: corretto11  
commands:  
- apt-get update  
- apt-get install -y jq  
- export SONAR\_SCANNER\_VERSION=4.4.0.2170  
- export SONAR\_SCANNER\_HOME=$HOME/.sonar/sonar-scanner-$SONAR\_SCANNER\_VERSION-linux  
- curl --create-dirs -sSLo $HOME/.sonar/sonar-scanner.zip [https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-$SONAR\_SCANNER\_VERSION-linux.zip](https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-%24SONAR_SCANNER_VERSION-linux.zip)  
- unzip -o $HOME/.sonar/sonar-scanner.zip -d $HOME/.sonar/  
- export PATH=$SONAR\_SCANNER\_HOME/bin:$PATH  
- export SONAR\_SCANNER\_OPTS="-server"  
pre\_build:  
commands:  
- sonar-scanner -Dsonar.organization=bilgeadamguney -Dsonar.projectKey=bilgeadamguney\_my-sonar-app -Dsonar.sources=src -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=$SONAR\_TOKEN  
- sleep 5  
- curl -u SONAR\_TOKEN https://sonarcloud.io/api/qualitygates/project\_status?projectKey=bilgeadamguney\_my-sonar-app \> analysis.json - cat analysis.json - if [(jq -r ‘.projectStatus.status’ analysis.json) = ERROR] ; then $CODEBUILD\_BUILD\_SUCCEEDING -eq 0 ;fi  
build:  
commands:  
- echo Building Project  
- echo Finished Building

cache:  
paths:  
- “node\_modules/\*\*/\*”

---

<div class="post-metadata">

**Author:** ![Alexandre\_Holzhey](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/alexandre_holzhey/32/74760_2.png) [@Alexandre\_Holzhey](https://community.sonarsource.com/u/Alexandre_Holzhey)\
**Post date:** [April 19, 2021, 9:35am UTC](https://community.sonarsource.com/t/sonarcloud-bitbucket-cloud-pull-request-branches-analyse/41645/2 "2021-04-19T09:35:58Z")

</div>

Hi @tahacanatak and welcome to our Community!

Looking at how you execute the scanner:

> sonar-scanner -Dsonar.organization=bilgeadamguney -Dsonar.projectKey=bilgeadamguney\_my-sonar-app -Dsonar.sources=src -Dsonar.host.url=[https://sonarcloud.io](https://sonarcloud.io) -Dsonar.login=$SONAR\_TOKEN

I see there is no information related to the pull request/branch to be analysed.

Since you are not using an SonarCloud-integrated CI you need to configure some additional parameters. You can check them [here](https://sonarcloud.io/documentation/branches/branch-details/), basically:

```
sonar.branch.name
sonar.branch.target

```

For pull requests (currently there is no documentation for it), you need to specify the parameter:

`sonar.pullrequest.key`

I hope that helps! Please come back if you need further help.

---

<div class="post-metadata">

**Author:** ![tahacanatak](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/tahacanatak/32/21220_2.png) [@tahacanatak](https://community.sonarsource.com/u/tahacanatak)\
**Post date:** [April 19, 2021, 10:07am UTC](https://community.sonarsource.com/t/sonarcloud-bitbucket-cloud-pull-request-branches-analyse/41645/4 "2021-04-19T10:07:12Z")

</div>

Hi Thank you so much.  
Help solved the problem using this.  
Is there any difference from what you suggest?

- sonar-scanner -Dsonar.organization=test  
-Dsonar.projectKey=my-sonar-app  
-Dsonar.sources=src  
-Dsonar.host.url=https://sonarcloud.io  
-Dsonar.login=$SONAR\_TOKEN  
-Dsonar.pullrequest.base=master  
-Dsonar.pullrequest.branch=CODEBUILDEXTRAS\_GIT\_BRANCH -Dsonar.pullrequest.key=(echo $CODEBUILD\_WEBHOOK\_TRIGGER | cut -c 4-5000)

---

<div class="post-metadata">

**Author:** ![Alexandre\_Holzhey](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/alexandre_holzhey/32/74760_2.png) [@Alexandre\_Holzhey](https://community.sonarsource.com/u/Alexandre_Holzhey)\
**Post date:** [April 19, 2021, 10:25am UTC](https://community.sonarsource.com/t/sonarcloud-bitbucket-cloud-pull-request-branches-analyse/41645/5 "2021-04-19T10:25:59Z")

</div>

You are welcome. Your approach is fine!

One remark: I would not send pull request information when doing an analysis on a long living branch, for example. If you do that, please change your script properly (not having such parameters). But i guess you are only analyzing pull requests this way, that is correct?

---

<div class="post-metadata">

**Author:** ![tahacanatak](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/tahacanatak/32/21220_2.png) [@tahacanatak](https://community.sonarsource.com/u/tahacanatak)\
**Post date:** [April 20, 2021, 8:20am UTC](https://community.sonarsource.com/t/sonarcloud-bitbucket-cloud-pull-request-branches-analyse/41645/6 "2021-04-20T08:20:16Z")

</div>

yes I only analyze pull requests.

I want to ask one more question.I use the same parameters when doing analysis in dotnet projects, but I get the following error.Are other parameters used in other pull request analyzes in dotnet projects?

Running command dotnet sonarscanner begin /k:ba.lms /o:guney /d:sonar.login=$SONAR\_TOKEN /d:sonar.host.url=https://sonarcloud.io /d:sonar.pullrequest.base=master /d:sonar.pullrequest.branch=$CODEBUILDEXTRAS\_GIT\_BRANCH /d:sonar.pullrequest.key=$PULL\_REQUEST\_NUMBER /d:sonar.verbose=true

164 SonarScanner for MSBuild 5.2  
165 Using the .NET Core version of the Scanner for MSBuild  
166 **The format of the analysis property sonar.pullrequest.branch= is invalid**  
167 Default properties file was found at /root/.dotnet/tools/.store/dotnet-sonarscanner/5.2.0/dotnet-sonarscanner/5.2.0/tools/net5.0/any/SonarQube.Analysis.xml

---

<div class="post-metadata">

**Author:** ![tahacanatak](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/tahacanatak/32/21220_2.png) [@tahacanatak](https://community.sonarsource.com/u/tahacanatak)\
**Post date:** [April 20, 2021, 10:52am UTC](https://community.sonarsource.com/t/sonarcloud-bitbucket-cloud-pull-request-branches-analyse/41645/7 "2021-04-20T10:52:40Z")

</div>

When I run it without assigning variables to parameters, as stated below, I do not get an error. but I have to set it as a variable. I guess I’m making a syntax error

dotnet sonarscanner begin /k:ba.lms / o: guney /d:sonar.login=$SONAR\_TOKEN/d:sonar.host.url=https://sonarcloud.io /d:sonar.pullrequest.base=master / d : sonar.pullrequest.branch = feature / analysis-test2 /d:sonar.pullrequest.key=642 /d:sonar.verbose=true

---

<div class="post-metadata">

**Author:** ![Alexandre\_Holzhey](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/alexandre_holzhey/32/74760_2.png) [@Alexandre\_Holzhey](https://community.sonarsource.com/u/Alexandre_Holzhey)\
**Post date:** [April 20, 2021, 12:20pm UTC](https://community.sonarsource.com/t/sonarcloud-bitbucket-cloud-pull-request-branches-analyse/41645/8 "2021-04-20T12:20:52Z")

</div>

@tahacanatak you are welcome!

Could you provide the value of this parameter:

> [@tahacanatak](#):
>
> $CODEBUILDEXTRAS\_GIT\_BRANCH

---

<div class="post-metadata">

**Author:** ![tahacanatak](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/tahacanatak/32/21220_2.png) [@tahacanatak](https://community.sonarsource.com/u/tahacanatak)\
**Post date:** [April 20, 2021, 12:41pm UTC](https://community.sonarsource.com/t/sonarcloud-bitbucket-cloud-pull-request-branches-analyse/41645/9 "2021-04-20T12:41:34Z")

</div>

value is null ☹ the problem was caused by the plug I used.Thank you again. 🙂

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/system/32/31083_2.png) [@system](https://community.sonarsource.com/u/system)\
**Post date:** [April 27, 2021, 12:42pm UTC](https://community.sonarsource.com/t/sonarcloud-bitbucket-cloud-pull-request-branches-analyse/41645/10 "2021-04-27T12:42:21Z")

</div>

Closed on April 27, 2021, 12:42pm UTC

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
