We currently maintain our source code and do pull requests in Azure Devops. We DO NOT use Azure piplines but rather Team City. That’s working great. Code and results show proper in SonarCloud, both long lived and PR branches.
We want to start decorating our Pull Requests with the results; however, it’s not working. In SonarCloud, we’ve enabled Pull Requests, we’ve set the Provider and Personal Access Token.
We analyze the project using the following parameters:
You should rely on what’s set in SonarCloud, rather than provide a token during analysis. I believe this is something that is no longer even supported (it was never documented, either)
This all looks fine assuming the values resolve correctly. Is your org/project bound?
I removed the token from the analysis; however, it made no difference. I do have the organization bound and the values resolve properly. Just to test, I removed the Personal Access Token from the project to see if that would make a difference, but it didn’t either. Here are some logs from the run and I don’t see anything out of the ordinary.
06:21:51 Calling the SonarScanner CLI...
06:21:51 INFO: Scanner configuration file: /root/.dotnet/tools/.store/dotnet-sonarscanner/9.0.2/dotnet-sonarscanner/9.0.2/tools/netcoreapp3.1/any/sonar-scanner-5.0.1.3006/conf/sonar-scanner.properties
06:21:51 INFO: Project root configuration file: /home/ubuntu/work/68ef25abd92dbaa1/src/WebApps/MyProject/.sonarqube/out/sonar-project.properties
06:21:51 INFO: SonarScanner 5.0.1.3006
06:21:51 INFO: Java 17.0.13 Amazon.com Inc. (64-bit)
06:21:51 INFO: Linux 6.8.0-1019-aws amd64
06:21:51 INFO: User cache: /root/.sonar/cache
06:21:52 INFO: Analyzing on SonarCloud
06:21:52 INFO: Default locale: "en", source code encoding: "UTF-8" (analysis is platform dependent)
06:21:52 INFO: Load global settings
06:21:53 INFO: Load global settings (done) | time=566ms
06:21:53 INFO: Server id: 1BD809FA-AWHW8ct9-T_TB3XqouNu
06:21:53 INFO: Loading required plugins
06:21:53 INFO: Load plugins index
06:21:53 INFO: Load plugins index (done) | time=206ms
06:21:53 INFO: Load/download plugins
06:21:53 INFO: Load/download plugins (done) | time=57ms
06:21:54 INFO: Load project settings for component key: '************'
06:21:54 INFO: Load project settings for component key: '************' (done) | time=176ms
06:21:54 INFO: Process project properties
06:21:54 INFO: Project key: '************'
06:21:54 INFO: Base dir: /home/ubuntu/work/68ef25abd92dbaa1/src/WebApps/MyProject
06:21:54 INFO: Working dir: /home/ubuntu/work/68ef25abd92dbaa1/src/WebApps/MyProject/.sonarqube/out/.sonar
06:21:54 INFO: Load project branches
06:21:54 INFO: Load project branches (done) | time=308ms
06:21:54 INFO: Check ALM binding of project ''************''
06:21:54 INFO: Detected project binding: BOUND
06:21:54 INFO: Check ALM binding of project ''************'' (done) | time=155ms
06:21:54 INFO: Load project pull requests
06:21:55 INFO: Load project pull requests (done) | time=313ms
06:21:55 INFO: Load branch configuration
06:21:55 INFO: Load branch configuration (done) | time=324ms
06:21:55 INFO: Load quality profiles
06:21:55 INFO: Load quality profiles (done) | time=330ms
06:21:55 INFO: Load active rules
06:22:04 INFO: Load active rules (done) | time=9011ms
06:22:05 INFO: Organization key: ************
06:22:05 INFO: Pull request 4528 for merge into develop from feature/lla-4411
06:22:05 INFO: Preprocessing files...
06:22:05 INFO: 5 languages detected in 868 preprocessed files
06:22:05 INFO: 1010 files ignored because of inclusion/exclusion patterns
06:22:05 INFO: 22 files ignored because of scm ignore settings
06:22:05 INFO: Loading plugins for detected languages
06:22:05 INFO: Load/download plugins
06:22:05 INFO: Load/download plugins (done) | time=22ms
06:22:05 INFO: Executing phase 2 project builders
06:22:05 INFO: Executing phase 2 project builders (done) | time=17ms
06:22:05 INFO: Load project repositories
06:22:06 INFO: Load project repositories (done) | time=454ms
06:22:06 INFO: SCM collecting changed files in the branch
06:22:06 INFO: SCM collecting changed files in the branch (done) | time=98ms
06:22:06 INFO: Indexing files...
06:22:18 INFO: Analysis report generated in 370ms, dir size=568 KB
06:22:18 INFO: Analysis report compressed in 114ms, zip size=365 KB
06:22:20 INFO: Analysis report uploaded in 1405ms
06:22:20 INFO: ------------- Check Quality Gate status
06:22:20 INFO: Waiting for the analysis report to be processed (max 300s)
06:22:25 INFO: QUALITY GATE STATUS: PASSED - View details on https://sonarcloud.io/dashboard?id=***********&pullRequest=4528
06:22:25 INFO: Time spent writing ucfgs 0ms
06:22:25 INFO: Analysis total time: 32.008 s
06:22:25 INFO: ------------------------------------------------------------------------
06:22:25 INFO: EXECUTION SUCCESS
06:22:25 INFO: ------------------------------------------------------------------------
06:22:25 INFO: Total time: 34.780s
06:22:26 INFO: Final Memory: 55M/194M
06:22:26 INFO: ------------------------------------------------------------------------
06:22:26 The SonarScanner CLI has finished
06:22:26 13:22:26.374 Post-processing succeeded.
06:22:26 Process exited with code 0
After looking in the logs, I think I know what’s going on, and it matches an issue reported a while ago (August 2023)
Basically, we still are relying on parameters that get automatically filled when using the Azure DevOps Extension instead of relying on the binding. The ticket to rely on the data from the binding is still open. I know it’s something we plan to work on sooner than later.
For now, you can pass those additional three parameters and you should have PR decoration working.