Error when applying SonarCloudQualityGateCheck to Azure DevOps

We’ve successfully integrated Sonarcloud analysis into our Azure DevOps build pipeline using the SonarCloudPrepare, SonarCloudAnalyze and SonarCloudPublish tasks.

We want to make the pipeline fail when the Sonarcloud Quality gate checks fail. We found the SonarCloudQualityGateCheck task which sounds like just what we need. However, when adding this task to the pipeline and running it, it fails with the following error message:

“Job Build: Step references task ‘SonarCloudQualityGateCheck’ at version ‘1.0.0’ which is not valid for the given job target.”

In the yaml file defining our pipeline, this task is set up as “- task: SonarCloudQualityGateCheck@1”. This is what the pipeline editor gui produced when adding the “SonarCloud Quality Gate status check” task. We’ve experimented with several varations of the yaml pipeline definitin script without luck. This is the yaml definition for our Build stage:

- stage: Build
  jobs:
  - job: Build
    pool:
      vmImage: 'ubuntu-latest'
    variables:
      buildConfiguration: 'Release'
    steps:
    - task: SonarCloudPrepare@1
      inputs:
        SonarCloud: 'sonarcloud'
        organization: '<our org>'
        scannerMode: 'MSBuild'
        projectKey: 'orbit-portal-api'
        projectName: 'orbit-portal-api'
    - script: dotnet build --configuration $(buildConfiguration)
      displayName: 'dotnet build $(buildConfiguration)'
    - task: DotNetCoreCLI@2
      inputs:
        command: test
        projects: '**/*Tests/*.csproj !**/*IntegrationTests/*.csproj'
        arguments: '--configuration $(buildConfiguration)'
    - task: SonarCloudAnalyze@1
    - task: SonarCloudPublish@1
      inputs:
        pollingTimeoutSec: '300'
    - task: SonarCloudQualityGateCheck@1
    - task: Docker@2
      inputs:
        containerRegistry: '<our registry>'
        repository: 'orbit-portal-api'
        command: 'buildAndPush'
        Dockerfile: '**/Dockerfile'
        tags: 'dev.$(Build.BuildNumber)'

We’ve found the definition for the extension at https://github.com/SonarSource/sonar-scanner-vsts/blob/master/extensions/sonarcloud/tasks/qgstatus/new/task.json. We notice that SonarCloudQualityGateCheck has

  "category": "Deploy",
  "visibility": ["Release"],

whereas the three other tasks have

  "category": "Build",
  "visibility": ["Build"],

Inspired by this difference, we’ve tried to use the quality gate check task in a “deployment” rather than a regular “job” in our pipeline, but without any luck. Is the step intended to be a part of a Release pipeline rather than a normal/Build pipeline? Our pipeline includes both building av deployment, so we’re not using Release pipelines. And anyway, we would like to make the build fail, also in cases when there is no deployment (e.g. when building feature branches).

PS: We’ve successfully installed the Sonarcloud application in GitHub, and the status of the sonarcloud analysis shows up as a part of the pull request checks. But we’d also like to fail the build when the quality requirements are not met.

PPS: the SonarCloudPublish task adds “SonarCloud Analysis Report” to the “Extensions” tab on our pipeline status page, and it works fine. But the analysis report shows up twice on the page, like this:

SonarCloud Analysis Report
orbit-portal-api Quality Gate Passed
Detailed SonarCloud report > 

SonarCloud Analysis Report
orbit-portal-api Quality Gate Passed
Detailed SonarCloud report > 

The double analysis report is not a big deal, just wanted to let the Sonarcloud team know about it.

Hi and welcome to the community !

The SonarCloud Quality Gate check is a newest addition in the Azure DevOps extensions, and is intended to be use as a Pre-Deployment Gate in Release pipelines

There is a 3rd party extension for failing the build from the Quality Gate status, it’s called SonarCloud build breaker

We are aware of the cloned Analysis Report, another user has reached us for that. Unfortunately after having done a troubleshoot session we weren’t able to find the issue on our side, so this user has opened up a case on the Microsoft developer community forum (https://developercommunity.visualstudio.com/content/problem/733768/duplicate-analysis-report-displayed-on-extensions.html)

Thank you.

Mickaël

Hi. Thank you, Mickaël. We’ve applied the SonarCloud build breaker, and it works just as expected. :+1:

The duplicate Analysis report in the DevOps pipeline summary is no big issue for us. Actually, for the last few builds, it’s no longer duplicated. I can’t think of anything we’ve done to make it go away, but for now, it’s fine :slight_smile:

(We’re experiencing another problem related to the master branch becoming the parent of our feature branches, but I’ll open another request for that).

1 Like