PR scanning & PR decoration with GitHub and Azure Pipelines

Dear Sonar community,

let me provide some more context next to the template being filled out underneath. Those are the acceptance criteria for us:

  • Run Quality Gate check on every PR and block PR from merging if Quality Gate is violated
  • Add test coverage result to SonarCloud and use test coverage within the Quality Gate

We are currently using manual configuration of the analysis:

  • Easy for the developers to configure exclusions, test directories etc. in the code
  • Ingesting code coverage results while pipeline is running to use the results as Quality Gate
  • No built-in support for Scala which is most of our stack - example is TypeScript though

We have been trying to add parameters such as:


but it resulted in an error message:
A pull request analysis cannot have the branch analysis parameter ‘sonar-branch-name’

  • GitHub Enterprise Cloud as source control
  • Azure Pipelines for CI automation with the Sonar plugin available on the market place
  • Configuration of the pipeline in the project
          - template: Templates/SonarCloud-QualityScanning.yml@SonarCloud-QualityScanning
              sonarCloudProjectName: $(serviceName)
              sonarCloudProjectKey: ******_$(serviceName)
              sonarCloudPrepare: true
              sonarPreSteps: true
              sonarCloudAnalyze: true
              sonarCloudPublish: true
              sonarCloudSourceDir: ${{ parameters.sonarCloudSourceDir }}
              sonarCloudExtraProperties: |

Code inside the template:

  - ${{ if eq(parameters.sonarCloudPrepare, true) }}:
      - task: SonarCloudPrepare@1
        displayName: 'SonarCloud: Prepare analysis configuration'
            SonarCloud: 'sonarcloud'
            organization: ${{ parameters.sonarCloudOrganization }}
            scannerMode: 'CLI'
            ${{ if eq(parameters.sonarCloudEnableConfigFile, true) }}:
              configMode: 'file'
              configFile: $(parameters.sonarCloudConfigFile)
            ${{ if ne(parameters.sonarCloudExtraProperties, '') }}:
                extraProperties: |
                  ${{ parameters.sonarCloudExtraProperties }}
            ${{ if eq(parameters.sonarCloudEnableConfigFile, false) }}:
                cliProjectKey: ${{ parameters.sonarCloudProjectKey }}
                cliProjectName: ${{ parameters.sonarCloudProjectName }}
                cliProjectVersion: ${{ parameters.sonarCloudProjectVersion }}
                cliSources: ${{ parameters.sonarCloudSourceDir }}
                configMode: 'manual'

  - ${{ if eq(parameters.sonarCloudAnalyze, true) }}:
      - task: SonarCloudAnalyze@1
        displayName: 'SonarCloud: Run analysis'

  - ${{ if eq(parameters.sonarCloudPublish, true) }}:
      - task: SonarCloudPublish@1
        displayName: 'SounarCloud: Publish results'
          pollingTimeoutSec: '300'
  • TypeScript Java Script
  • SonarCloud is not public
  • Two problems observed:
  1. Pull Requests are not scanned at all
  2. As a consequence we we also do not PR decoration
  • Create PR on a project
  • Using automated analysis

Hi @andre.ostermeier

Those parameter are set automatically if we detect that this is a PullRequest, so you shouldn’t need to set them on your own.

For the parameter being set, can you please check, with debug enabled, if the value of System.PullRequest.PullRequestId variable on Azure Pipeline is set and has a value ?

Thank you.


you gave us the right hint.

The parameter was indeed empty and we added those lines on top of the Azure pipeline and then the parameter had the PR Id.

- main

Thanks for you help,

1 Like

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