Azure DevOps "Publish Quality Gate" task fail consistently with 404

Nearly all the time, on a PR analysis, the Publish Quality gate task fails with the following issue:

##[section]Starting: Publish Quality Gate Result
==============================================================================
Task         : Publish Quality Gate Result
Description  : Publish SonarCloud's Quality Gate result on the Azure Pipelines build result. To be used after the actual analysis.
Version      : 1.6.0
Author       : sonarsource
Help         : [More Information](http://redirect.sonarsource.com/doc/install-configure-scanner-tfs-ts.html)
==============================================================================
##[error][SQ] API GET '/api/ce/task' failed, status code was: 404
##[error][SQ] Could not fetch task for ID 'AWl3SVZ-rqukisAhSnNk'
##[section]Finishing: Publish Quality Gate Result

Strangely, the only SonarCloud analysis task has the following log:

INFO: More about the report processing at https://sonarcloud.io/api/ce/task?id=AWnaa_W1bZ-4oYCt1fPG

which is not the same id…
Looking at the SonarCloud project background tasks, I find AWnaa_W1bZ-4oYCt1fPG, but not the AWl3SVZ-rqukisAhSnNk the quality gate tries to get…

Can you please help ?

Does the build job contain several SonarCloud analysis tasks?

Hello,

Thanks for your interest in my issue.
The is a single analysis in the pipeline.

Here is the yaml:
pool:
name: Default
demands:
- DotNetFramework
- msbuild
- visualstudio
- vstest
- java

#Your build pipeline references the ‘BuildPlatform’ variable, which you’ve selected to be settable at queue time. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab, and then select the option to make it settable at queue time. See https://go.microsoft.com/fwlink/?linkid=865971
#Your build pipeline references the ‘BuildConfiguration’ variable, which you’ve selected to be settable at queue time. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab, and then select the option to make it settable at queue time. See https://go.microsoft.com/fwlink/?linkid=865971
#Your build pipeline references the ‘BuildPlatform’ variable, which you’ve selected to be settable at queue time. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab, and then select the option to make it settable at queue time. See https://go.microsoft.com/fwlink/?linkid=865971
#Your build pipeline references the ‘BuildConfiguration’ variable, which you’ve selected to be settable at queue time. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab, and then select the option to make it settable at queue time. See https://go.microsoft.com/fwlink/?linkid=865971
variables:
  application.name: 'SNIPPED'

steps:
- task: NuGetToolInstaller@0
  displayName: 'Use NuGet 4.5+'
  inputs:
    versionSpec: '>=4.5'

- task: NuGetCommand@2
  displayName: 'NuGet restore $(application.name).sln'
  inputs:
    restoreSolution: '$(application.name).sln'
    feedsToUse: config
    nugetConfigPath: nuget.config

#Task group has not been exported, task groups are not supported yet

- task: SonarSource.sonarcloud.14d9cde6-c1da-4d55-aa01-2965cd301255.SonarCloudPrepare@1
  displayName: 'Prepare analysis on SonarCloud'
  inputs:
    SonarCloud: 'SonarCloud SNIPPED'
    organization: 'SNIPPED'
    projectKey: SNIPPED
    projectName: SNIPPED

- task: VSBuild@1
  displayName: 'Build solution $(application.name).sln'
  inputs:
    solution: '$(application.name).sln'
    platform: '$(BuildPlatform)'
    configuration: '$(BuildConfiguration)'
    clean: true

- task: VSTest@2
  displayName: 'Run tests'
  inputs:
    testAssemblyVer2: |
     **\Yuc*test*.dll
     !**\*TestAdapter.dll
     !**\obj\**
    runInParallel: false
    runTestsInIsolation: true
    codeCoverageEnabled: true
    platform: '$(BuildPlatform)'
    configuration: '$(BuildConfiguration)'
    rerunFailedTests: false

- 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'
  continueOnError: true

The variables are set like this:

  1. BuildConfiguration: release
  2. BuildPlatform: any cpu

Regards,

Thanks for the details @Greybird.

I searched in the system and I could indeed find an existing task with AWnaa_W1bZ-4oYCt1fPG, but with AWl3SVZ-rqukisAhSnNk - which is strange.

IIRC, the task is searching for a report-analysis.txt file that is generated by the scanner when performing the analysis. Could it be that:

  • either your source code repository contains such a file, and the task takes it instead of the newly generated one?
  • or that there is some caching mechanism on your build definition which grabs files from previous builds, and here again the task does not pick the correct one?

Also, you say:

, does it imply that it works from time to time?

Hello,

I will check if such a file could be there.
Actually, it is consistent for a given pipeline definition, and the same project can have a different behavior on pr validation and on post merge builds.

I just checked the build agents, and I found a report-task.txt file in the .scannerwork directory which are quite old. In report-task.txt I find the id which the Publish Quality Gate step is using.
After removal of this file, which is probably a leftover from a previous hosted SonarQube instance, everything is working fine.

I would suggest that maybe some time check could be done on the file with regards to the time of analysis preparation for this.

Thanks a lot for your help anyway!

Arnaud

Great, I’m happy that you found the problem. Did you specifically add the .scannerwork folder in some list of caches, or is it something that was automatically done somehow by Azure Pipelines?

Hi,
I am facing the same issue, may i know how to remove/ find those folder .scanner work and file report-analysis.txt in azure pipelines (Microsoft self hosted agents) ?

Error:
##[error][SQ] API GET ‘/api/ce/task’ failed, status code was: 404

##[error][SQ] Could not fetch task for ID ‘AXPik0mHeYBwmY_kVYyU’

Regards
Vinay

1 Like

same error for maven build in VSTS extension for sonarqube