# Bitbucket Pipe + SonarCloud + C#/.net core

**URL:** <https://community.sonarsource.com/t/bitbucket-pipe-sonarcloud-c-net-core/7537>\
**Category:** SonarQube Cloud\
**Tags:** bitbucket, sonarqube-cloud\
**Created:** [March 6, 2019, 4:31pm UTC](https://community.sonarsource.com/t/bitbucket-pipe-sonarcloud-c-net-core/7537 "2019-03-06T16:31:17Z")\
**Posts on this page:** 1\
**Showing post:** 11

<div class="post-metadata">

**Author:** ![dibbdob](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/dibbdob/32/2901_2.png) [@dibbdob](https://community.sonarsource.com/u/dibbdob)\
**Post date:** [May 5, 2019, 7:29pm UTC](https://community.sonarsource.com/t/bitbucket-pipe-sonarcloud-c-net-core/7537/11 "2019-05-05T19:29:30Z")

</div>

I managed to get our particular pipeline working. The requirements were for the pipeline just to run and publish analysis of a C# .NET Core 2.2 app - the rest of the work was being done on Azure pipelines.

One issue we had was that java was not installed as we were using the microsoft/dotnet:sdk image. So I added a few additional command lines to download it - it would really have been nice to use an image that included dotnet **and** java so we don’t have to do this every time. We might create a custom image, but for now it’s not that big a deal.

The analysis works on all merge requests into dev in additional to all PRs  
First thing I created the project manually from our designated MAIN BRANCH by running the following commands from the root of a local copy of the repo (_replace the necessary properties_):

```
dotnet sonarscanner begin /k:"project.key" /d:"sonar.login=${SONAR_TOKEN}" /o:"organization-name" /d:"sonar.host.url=https://sonarcloud.io"
dotnet build App.sln
dotnet sonarscanner end /d:"sonar.login=${SONAR_TOKEN}"           

```

If you are building a project as opposed to a solution, then I think the project file needs to include a ProjectGuid.

Here is the **bitbucket-pipelines.yaml** file:

NOTE: If you want to analyse multiple branches use the format {dev, master, qa} - you get the idea

```
image: microsoft/dotnet:sdk

pipelines:
  branches:
    "{dev}":
      - step:
          name: Running SonarCloud Analysis
          services:
            - docker
          script:
            - apt-get update
            - apt-get install --yes --force-yes openjdk-8-jre
            - export PATH="$PATH:/root/.dotnet/tools"
            - dotnet tool install --global dotnet-sonarscanner
            - dotnet sonarscanner begin /k:"project.key" /d:"sonar.login=${SONAR_TOKEN}" /o:"organization-name" /v:"${BITBUCKET_COMMIT}" /d:"sonar.host.url=https://sonarcloud.io"
            - dotnet build App.sln
            - dotnet sonarscanner end /d:"sonar.login=${SONAR_TOKEN}"
  pull-requests:
      '**': #this runs as default for any branch not elsewhere defined in this script
      - step:
          name: Running SonarCloud Analysis
          services:
            - docker
          script:
            - apt-get update
            - apt-get install --yes --force-yes openjdk-8-jre
            - export PATH="$PATH:/root/.dotnet/tools"
            - dotnet tool install --global dotnet-sonarscanner
            - dotnet sonarscanner begin /k:"project.key" /d:"sonar.login=${SONAR_TOKEN}" /o:"organization-name" /v:"${BITBUCKET_COMMIT}" /d:"sonar.host.url=https://sonarcloud.io"
            - dotnet build App.sln
            - dotnet sonarscanner end /d:"sonar.login=${SONAR_TOKEN}"
definitions:
  services:
    docker:
      memory: 3072 # increase memory for docker-in-docker from 1GB to 3GB
```

---

_[View the full topic](https://community.sonarsource.com/t/bitbucket-pipe-sonarcloud-c-net-core/7537)._
