Quality gates (code coverage) fails when checkin from different branches

Hi,
when i check in from different branches it compares the code coverage from last checkin.
This makes the quality gate fails as it sais there is no code coverage on new lines added.

Is it possible somehow to make it only compare within the same branch?

Note that we run this in a dockerfile with command .

RUN yarn sonar

How can we add parameters for example sonar.pullrequest.branch and so on to be able to compare within pullrequests?

in a other project for .NET we could use this.

RUN if [ "$BUILD_REASON" = 'PullRequest' ] ; then \
      dotnet sonarscanner begin \
      /n:"Api" \
      /k:"$SONAR_PROJECT_KEY" \
      /v:"$SONAR_PROJECT_VERSION" \
      /o:"$SONAR_ORGANIZAION_KEY" \
      /d:sonar.scm.enabled=false \
      /d:sonar.host.url="$SONAR_HOST_URL" \
      /d:sonar.login="$SONAR_TOKEN" \
      /d:sonar.coverageReportPaths=./coveragereports/SonarQube.xml \
      /d:sonar.exclusions="*.xml, Source/MyProject.Legacy.ServiceStack.ServiceInterface/**, Source/BokaMera.Legacy.ServiceStack.ServiceModel/**, Source/BokaMera.Api.Host/Migrations/**, MyProject.Analyzers/**, **/TestResults/**, Tests/MyProject.Api.IntegrationTest/TestResults/**/coverage.opencover.xml,Source/MyProject.Remodeled.Cli/Sql/*.sql" \
      /d:sonar.qualitygate.wait=true \
      /d:sonar.pullrequest.base="$TARGET_BRANCH" \
      /d:sonar.pullrequest.branch="$SOURCE_BRANCH" \
      /d:sonar.pullrequest.key="$PULL_REQUEST_ID" \
      /d:sonar.pullrequest.provider=vsts \
      /d:sonar.pullrequest.vsts.instanceUrl="https://dev.azure.com/xxxxxxx/" \
      /d:sonar.pullrequest.vsts.project="Backend" \
      /d:sonar.pullrequest.vsts.repository="api" \
  ; else \
      dotnet sonarscanner begin \
      /n:"Api" \
      /k:"$SONAR_PROJECT_KEY" \
      /v:"$SONAR_PROJECT_VERSION" \
      /o:"$SONAR_ORGANIZAION_KEY" \
      /d:sonar.host.url="$SONAR_HOST_URL" \
      /d:sonar.login="$SONAR_TOKEN" \
      /d:sonar.coverageReportPaths=./coveragereports/SonarQube.xml \
      /d:sonar.exclusions="*.xml" \
      /d:sonar.qualitygate.wait=true \
      /d:sonar.scm.enabled=false \
  ; fi

Hi @krillehbg welcome to the community.

Comparing to same branch is possible, i think you just have to analysis multiple commits within your branch, and the results on SonarCloud will be (still compared to master), but accessible for that branch only (and you can use the measures / activity tab to have the history of certain metrics).

For the parameters, i’d suggest to use a sonar-project.properties files, located in the root folder of your project, that should work.

HTH,
Mickaël