Azure devops - build fails randomly with - Could not find the pullrequest with key x

Hi Community

We have just started out using SonarCloud with Azure dev-ops and we are still learning.

Our build pipeline works as expected most of the time, but it happens that build fails in our Run Code Analysis step. When it fails it is often enough to run the pipeline (based on yaml) once more and everything works as expected.

This is the error that we are getting:

INFO: Load project pull requests
INFO: Load project pull requests (done) | time=30ms
INFO: Load branch configuration
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 29.027s
INFO: Final Memory: 6M/24M
INFO: ------------------------------------------------------------------------
##[error]ERROR: Error during SonarScanner execution
ERROR: Could not find the pullrequest with key ‘67’
ERROR: Caused by: Error 404 on https://sonarcloud.io/api/alm_integration/show_pullrequest?project=UneegSW_Marco&pullrequestKey=67 : {“errors”:[{“msg”:“Requested resource wasn’t found on Azure DevOps.”,“reason”:“AZURE_DEVOPS_UNABLE_TO_FETCH_REQUESTED_RESOURCE”}]}
ERROR:
ERROR: Error during SonarScanner execution
ERROR: Could not find the pullrequest with key ‘67’
ERROR: Caused by: Error 404 on https://sonarcloud.io/api/alm_integration/show_pullrequest?project=UneegSW_Marco&pullrequestKey=67 : {“errors”:[{“msg”:“Requested resource wasn’t found on Azure DevOps.”,“reason”:“AZURE_DEVOPS_UNABLE_TO_FETCH_REQUESTED_RESOURCE”}]}

ERROR:
##[error]The SonarScanner did not complete successfully
The SonarScanner did not complete successfully
##[error]11:19:28.68 Post-processing failed. Exit code: 1
11:19:28.68 Post-processing failed. Exit code: 1
##[error]The process ‘D:\a_tasks\SonarCloudPrepare_14d9cde6-c1da-4d55-aa01-2965cd301255\1.19.0\classic-sonar-scanner-msbuild\SonarScanner.MSBuild.exe’ failed with exit code 1
Finishing: SonarCloudAnalyze

Our YAML steps looks like this:

        - task: SonarCloudPrepare@1
      inputs:
        SonarCloud: 'SonorCloud'
        organization: '***'
        scannerMode: 'MSBuild'
        projectKey: '***'
        projectName: '***'

    - task: XamarinAndroid@1
      inputs:
        projectFile: '**/*droid*.csproj'
        outputDirectory: '$(outputDirectory)'
        configuration: '$(buildConfiguration)'

    - task: SonarCloudAnalyze@1

SonarCloud extension - 1.23.0
Bitbucket cloud
SonarCloudPrepare@1

Any help would be highly appreciated.

Best regards
Simon

Hey @SimonBrettschneider,

Welcome to the community and apologies for the late reply!

This kind of error is being thrown only when the pull request that you are referring to with the pull request key was not created on the Azure before analysis. Can it be the case in your setup? Is the pull request always created before you run the analysis?

I have one more question. You mentioned Bitbucket Cloud and Azure, are you using azure pipelines to analyze the code and bitbucket as a code repository? Or everything is done in Azure?

Best,
Marcin