Azure DevOps Pipeline analysis of GitHub repo failing on PRs

  • ALM used: Azure DevOps with GitHub repo
  • CI system used: Azure DevOps
  • Scanner command used:
        - task: SonarCloudPrepare@1
          displayName: "Prepare SonarCloud analysis"
          inputs:
            SonarCloud: 'SC'
            organization: '***'
            scannerMode: 'CLI'
            configMode: 'manual'
            cliProjectKey: '***'
            cliProjectName: '***'
            cliSources: '.'
            extraProperties: |
              # Additional properties that will be passed to the scanner, 
              sonar.exclusions=.storybook/*
  • Languages of the repository: TypeScript
  • Error observed
Starting: Run SonarCloud analysis
==============================================================================
Task         : Run Code Analysis
Description  : Run scanner and upload the results to the SonarCloud server.
Version      : 1.38.0
Author       : sonarsource
Help         : Version: 1.38.0. This task is not needed for Maven and Gradle projects since the scanner should be run as part of the build.

[More Information](https://docs.sonarcloud.io/advanced-setup/ci-based-analysis/sonarcloud-extension-for-azure-devops/)
==============================================================================
/home/vsts/work/_tasks/SonarCloudAnalyze_ce096e50-6155-4de8-8800-4221aaeed4a1/1.38.0/sonar-scanner/bin/sonar-scanner
INFO: Scanner configuration file: /home/vsts/work/_tasks/SonarCloudAnalyze_ce096e50-6155-4de8-8800-4221aaeed4a1/1.38.0/sonar-scanner/conf/sonar-scanner.properties
INFO: Project root configuration file: NONE
INFO: SonarScanner 4.8.0.2856
INFO: Java 11.0.19 Eclipse Adoptium (64-bit)
INFO: Linux 5.15.0-1038-azure amd64
INFO: User cache: /home/vsts/.sonar/cache
INFO: Analyzing on SonarCloud
INFO: Default locale: "en", source code encoding: "UTF-8" (analysis is platform dependent)
INFO: Load global settings
INFO: Load global settings (done) | time=148ms
INFO: Server id: 1BD809FA-AWHW8ct9-T_TB3XqouNu
INFO: User cache: /home/vsts/.sonar/cache
INFO: Load/download plugins
INFO: Load plugins index
INFO: Load plugins index (done) | time=139ms
INFO: Load/download plugins (done) | time=22163ms
INFO: Loaded core extensions: developer-scanner
INFO: Found an active CI vendor: 'Azure DevOps'
INFO: Load project settings for component key: '***'
INFO: Load project settings for component key: '***' (done) | time=106ms
INFO: Process project properties
INFO: Execute project builders
INFO: Execute project builders (done) | time=1ms
INFO: Project key: ***
INFO: Base dir: /home/vsts/work/1/s
INFO: Working dir: /home/vsts/work/1/s/.scannerwork
INFO: Load project branches
INFO: Load project branches (done) | time=131ms
INFO: Check ALM binding of project '***'
INFO: Detected project binding: BOUND
INFO: Check ALM binding of project '***' (done) | time=109ms
INFO: Load project pull requests
INFO: Load project pull requests (done) | time=122ms
INFO: Load branch configuration
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 26.315s
INFO: Final Memory: 20M/70M
INFO: ------------------------------------------------------------------------
##[error]ERROR: Error during SonarScanner execution
ERROR: Could not find the pullrequest with key '3'
ERROR: Caused by: Error 404 on https://sonarcloud.io/api/alm_integration/show_pullrequest?project=***&pullrequestKey=3 : {"errors":[{"msg":"Unable to find the pullrequest with key \u00273\u0027"}]}
ERROR: 
ERROR: Re-run SonarScanner using the -X switch to enable full debug logging.
ERROR: Error during SonarScanner execution
ERROR: Could not find the pullrequest with key '3'
ERROR: Caused by: Error 404 on https://sonarcloud.io/api/alm_integration/show_pullrequest?project=***&pullrequestKey=3 : {"errors":[{"msg":"Unable to find the pullrequest with key \u00273\u0027"}]}
ERROR: 
ERROR: Re-run SonarScanner using the -X switch to enable full debug logging.
##[error]The process '/home/vsts/work/_tasks/SonarCloudAnalyze_ce096e50-6155-4de8-8800-4221aaeed4a1/1.38.0/sonar-scanner/bin/sonar-scanner' failed with exit code 2
Finishing: Run SonarCloud analysis

We’re required to use a GitHub repo with an Azure DevOps Pipeline for this project, but PR builds are failing with the Unable to find the pullrequest with key error shown above - I created the SonarCloud project manually (we’re an Azure DevOps-based organisation, so the wizard could not browse the available GitHub repos).

I guess SonarCloud is not able to retrieve details of the GitHub PRs in this scenario. Is this is a supported configuration?

HI @phildye

First of all sorry for the delay.

Our product expects the organization to be bound to where the code lives, not where the code is built. In this case, the organization should be bound to Github, not Azure.

In order to confirm this is the issue, could you run your Azure pipeline in debug mode (sonar.verbose=true) and provide the logs (redacted if necessary)

As changing the organization’s binding is not possible, below are some suggestions

We will also investigate if it is possible to make the pipeline able to locate the PR in Github. We will come back to you with more details on that.

Hi @phildye

Your pattern is not a supported use case: CI on Azure DevOps and source code in Github.

The only solution I see is to have a new organization bound to Github

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