Error while running code analysis on automated PR CI in Azure DevOps

  • ALM used - Azure DevOps
  • CI system used - Azure DevOps
  • Languages of the repository - TypeScript
    I am trying to integrate a SonarCloud analysis into my CI pipeline.
    When kicking the pipeline in manual mode for a short-living branch, everything is working just fine, I am seeing the short-living branch being analyzed properly and all the statistics is being shown in sonarcloud dashboard.
    But when I create a PR and the same exact pipeline is starting to run, I am getting the following errors during the Code Analysis step of the PR:
==============================================================================
Task         : Run Code Analysis
Description  : Run scanner and upload the results to the SonarCloud server.
Version      : 1.23.0
Author       : sonarsource
Help         : Version: 1.23.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://sonarcloud.io/documentation/analysis/scan/sonarscanner-for-azure-devops/)
==============================================================================
/home/vsts/work/_tasks/SonarCloudAnalyze_ce096e50-6155-4de8-8800-4221aaeed4a1/1.23.0/sonar-scanner/bin/sonar-scanner
INFO: Scanner configuration file: /home/vsts/work/_tasks/SonarCloudAnalyze_ce096e50-6155-4de8-8800-4221aaeed4a1/1.23.0/sonar-scanner/conf/sonar-scanner.properties
INFO: Project root configuration file: NONE
INFO: SonarScanner 4.6.1.2450
INFO: Java 11.0.11 AdoptOpenJDK (64-bit)
INFO: Linux 5.8.0-1039-azure amd64
INFO: User cache: /home/vsts/.sonar/cache
INFO: Scanner configuration file: /home/vsts/work/_tasks/SonarCloudAnalyze_ce096e50-6155-4de8-8800-4221aaeed4a1/1.23.0/sonar-scanner/conf/sonar-scanner.properties
INFO: Project root configuration file: NONE
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=671ms
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=155ms
INFO: Load/download plugins (done) | time=26493ms
INFO: Loaded core extensions: developer-scanner
INFO: Found an active CI vendor: 'Azure DevOps'
INFO: Load project settings for component key: 'XXXXXXXXX'
INFO: Load project settings for component key: 'XXXXXXXXX' (done) | time=138ms
INFO: Process project properties
INFO: Execute project builders
INFO: Execute project builders (done) | time=1ms
INFO: Project key: XXXXXXXXXX
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=129ms
INFO: Check ALM binding of project 'XXXXXXXX'
INFO: Detected project binding: BOUND
INFO: Check ALM binding of project 'XXXXXXXXXX' (done) | time=121ms
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: 32.797s
INFO: Final Memory: 7M/24M
INFO: ------------------------------------------------------------------------
##[error]ERROR: Error during SonarScanner execution
ERROR: Not authorized. Please check the properties sonar.login and sonar.password.
ERROR: 
ERROR: Re-run SonarScanner using the -X switch to enable full debug logging.
ERROR: Error during SonarScanner execution
ERROR: Not authorized. Please check the properties sonar.login and sonar.password.
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.23.0/sonar-scanner/bin/sonar-scanner' failed with exit code 2
Finishing: Run SonarCloud Code Analysis

Any help would be appreciated since I have no idea how to continue - the Azure DevOps Run Code Analysis task does not accept any parameters and the same exact pipeline while being kicked manually, works just fine

Thanks

After further investigation and adding verbose logging to the scanner, I have found that the error is coming from the API call to

02:56:20.436 INFO: Load branch configuration
02:56:20.436 DEBUG: Found manual configuration of branch/PR analysis. Skipping automatic configuration.
02:56:20.736 DEBUG: GET 401 https://sonarcloud.io/api/alm_integration/show_pullrequest?project=XXXXXXX&pullrequestKey=1933 | time=298ms
02:56:20.743 INFO: ------------------------------------------------------------------------
02:56:20.743 INFO: EXECUTION FAILURE

the interesting part is that the previous calls to the API resulted in HTTP 200

02:56:20.122 INFO: Load project branches
02:56:20.229 DEBUG: GET 200 https://sonarcloud.io/api/project_branches/list?project=XXXXXX | time=107ms
02:56:20.234 INFO: Load project branches (done) | time=112ms

Ok, so I figured it out - the problem was invalid PAT on the organizational level, after creating a new token, the API call resulted in HTTP 200

1 Like

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