1

We have build pipeline in Azure DevOps that contains two jobs that build two projects from the same repo (angular frontend and java backend). Very much abbreviated the build pipeline looks like this. This build pipeline is also used for Build Validation policy on PRs.

trigger:
  - develop

jobs:
  - job: Backend
    steps:
...
      - task: SonarCloudPrepare@1
        displayName: "Prepare analysis on SonarCloud"
        inputs:
          SonarCloud: OurProject
          organization: ourorg
          scannerMode: Other
          extraProperties: |
            sonar.exclusions=**/jalo/**,**/constants/**,**/*Standalone.java,**/_ui-src/**
            sonar.projectKey=backendproj
            sonar.projectName=xxxBackend

      - task: Gradle@2
        inputs:
          sonarQubeRunAnalysis: true

      - task: SonarCloudPublish@1

  - job: Frontend
    steps:
...    
      - task: SonarSource.sonarcloud.14d9cde6-c1da-4d55-aa01-2965cd301255.SonarCloudPrepare@1
        displayName: "Prepare analysis on SonarCloud"
        inputs:
          SonarCloud: OurProj
          organization: ourorg
          scannerMode: CLI
          configMode: manual
          cliProjectKey: FrontendKey
          cliProjectName: xxxFrontend
          cliSources: "somepath"
          extraProperties: |
            sonar.exclusions=**/src/webApplicationInjector.js,**/node_modules/*

...    
      - task: SonarSource.sonarcloud.ce096e50-6155-4de8-8800-4221aaeed4a1.SonarCloudAnalyze@1
        displayName: "Run Code Analysis"

      - task: SonarSource.sonarcloud.38b27399-a642-40af-bb7d-9971f69712e8.SonarCloudPublish@1
        displayName: "Publish Quality Gate Result"

When opening the build run by the PR we see these statuses:

enter image description here

But when opening the PR we see this:

enter image description here

When clicking the "Quality gate passed" it links to Frontpage Sonarcloud project, which in this case was successful.

Is it possible that both jobs are posting their statuses with the same name, i.e."SonarCloud/quality gate" and thereby is only the one finishing last being checked by the policy?

enter image description here

Mathias Rönnlund
  • 4,078
  • 7
  • 43
  • 96
  • According to your description, two jobs in your pipeline use two source repos, so do you set the branch policy for the target branches in both repos? – Hugh Lin Jul 06 '20 at 10:28
  • Actually, there is only one repo that contains both the angular frontend and java backend. I’ll update the question. L – Mathias Rönnlund Jul 06 '20 at 11:20
  • I tested it, on my side everything works well. – Hugh Lin Jul 09 '20 at 02:16
  • 1
    @MathiasRönnlund any chance that you've found a solution to this issue? I'm experiencing the same. 2 quality gates get published on the pipeline, however, I only see one option when trying to add a status policy to a branch. The answer given by Hugh Lin - MSFT doesn't look right, as it seems that the failed gate is applied twice in the PR check and the passed gate is ignored. What we need is most likely a way to name the gate results when publishing them in the pipeline so that the distinction can be made between the two. Thanks for your reply in advance! – jurgenvo Mar 26 '21 at 15:15
  • @jurgenvo Unfortunately no success on this, we are still only seeing one status published.I now setup a test project for this: https://dev.azure.com/mirkadev/TwoSonarProblem/_build and in sonarcloud https://sonarcloud.io/dashboard?id=TwoSonarProblem-Project1 and https://sonarcloud.io/dashboard?id=TwoSonarProblem-Project2 – Mathias Rönnlund Mar 29 '21 at 08:43

1 Answers1

1

I tested it on my side. If one of the SonarCloud Analysis Report statues fails, the pull request Quality Gate will also become failed.

enter image description here

enter image description here

Branch policy:

enter image description here

Here is a document you can refer to.

Hugh Lin
  • 17,829
  • 2
  • 21
  • 25
  • This is still not working for us. We see both statuses published on the build but only one status is selectable in branch policies. I now setup a test project for this: dev.azure.com/mirkadev/TwoSonarProblem/_build and in sonarcloud sonarcloud.io/dashboard?id=TwoSonarProblem-Project1 and sonarcloud.io/dashboard?id=TwoSonarProblem-Project2. Maybe you could take a look? – Mathias Rönnlund Mar 29 '21 at 08:45