PR Build Validation - Analysis is generating a empty "analysis" at SonarCloud

  • ALM used: Azure DevOps
  • CI system used: Azure DevOps
  • It’s a Private Project
  • Using Source File Inclusions
  • Languages of the repository PL/SQL
  • Error observed
    So, similarly to this topic PR analysis is always empty

I have a Branch with “new codes” generating a issue, so the idea was to test the PR comments function. But when the Azure DevOps triggers the PR build to be validated, it is always returning a “successful” analysis but there is no code analysed in SonarCloud UI.

For example, running the pipeline directly to the source branch it gives the correct analysis:
Pipeline manually started specifying a branch:
image

Extension tab at build run
image

At SonarCloud

So at least when I’m running the pipeline and refering to a specific branch, it is running as intended. It generates the comments in PR and the New Codes are in the SonarCloud UI Analysis

But when the runs is started direcly from the automated PR build validation, it is always returning a completed analysis but with no code analysed.

build automated generated by PR


Extension tab at build run:
image

At SonarCloud

First time I was thinking the problem was related to sonarcloud.properties but they are getting the correct values from PullRequests in “Background Tasks”. But now i don’t know what it could be.

The thing is, I’m guess the problem is somehow related to the git clone process, because when running the Pipeline with the default clone from azure it get as expected the new code analysis with the Issue reported. But I have a custom git clone process because our repository is really huge, so we needed a custom clone to get only the current commit and nothing more ( a normal Azure Shallow clone is around 10minutes of “git clone”, with the custom clone bellow is around 3-4minutes ).

$env:GIT_TRACE_PACKET=1
$env:GIT_TRACE=1

Write-Host "Cloning repos at: "
Get-Location
# Criando pasta do GIT
If(!(Test-Path ".git"))
{
 git init
 git config --global core.longpaths true
}


Write-Host "Adicionado a branch $(BranchFullName) com as refs da branch remota"

Write-Host "Fetching $(BranchFullName) com Shallow Clone"

#verificar se é uma TAG ou uma branch
if("$(BranchFullName)" -match '^v\d+\.\d+\.\d+'){
git remote add origin `
 "https://$(System.AccessToken)@dev.azure.com/{organizationName}/{ProjectName}/_git/$(Build.Repository.Name)"

git fetch origin tag $(BranchFullName) --depth 1 --no-tags --progress; git checkout tags/$(BranchFullName)
} elseif ( "$(BranchFullName)".Contains("refs/pull")) {

$branchName = "$(System.PullRequest.SourceBranch)".Replace("refs/heads/", "").Replace("refs/tags/","")
git remote add -t $(BranchFullName) origin `
 "https://$(System.AccessToken)@dev.azure.com/{organizationName}/{ProjectName}/_git/$(Build.Repository.Name)"
git fetch --progress --depth 1; git checkout origin/$(BranchFullName) -b $(BranchFullName)
git branch -a
git pull origin $(BranchFullName) --allow-unrelated-histories
}
else {
git remote add -t $(BranchFullName) origin `
 "https://$(System.AccessToken)@dev.azure.com/{organizationName}/{ProjectName}/_git/$(Build.Repository.Name)"
git fetch --progress --depth 1; git checkout origin/$(BranchFullName) -b $(BranchFullName)
git branch -a
git pull origin $(BranchFullName) --allow-unrelated-histories
}

exit

So the PR automated always gonna do the “else if” statement. I already tried to add one more branch ( master ) to see if something changes, but the problem persists. Is there anything related to git clone or commits, history or anything like that SonarCloud needs in the local repository which I don’t know ?

Log of Sonar Run Code Analysis when the PR automated build creates a run in Azure Devops using Default Clone

INFO: Pull request 26653 for merge into master from USING_SONAR
INFO: Preprocessing files...
INFO: 1 language detected in 185 preprocessed files
INFO: 10785 files ignored because of inclusion/exclusion patterns
INFO: 0 files ignored because of scm ignore settings
INFO: Loading plugins for detected languages
INFO: Load/download plugins
INFO: Load/download plugins (done) | time=53ms
INFO: Load project repositories
INFO: Load project repositories (done) | time=409ms
INFO: SCM collecting changed files in the branch
WARN: Could not find ref: master in refs/heads, refs/remotes/upstream or refs/remotes/origin
INFO: SCM collecting changed files in the branch (done) | time=45ms
INFO: Indexing files...
INFO: Project configuration:
INFO:   Included sources: src/oracle/packages/*, src/oracle/procedures/*, src/oracle/functions/*
INFO:   Excluded sources: **/build-wrapper-dump.json
INFO: 185 files indexed
INFO: Quality profile for plsql: Sonar way
INFO: ------------- Run sensors on module TopManager.V12
INFO: Load metrics repository
INFO: Load metrics repository (done) | time=371ms
INFO: Sensor cache enabled
INFO: Load sensor cache
INFO: Load sensor cache (404) | time=403ms
INFO: Sensor JaCoCo XML Report Importer [jacoco]
INFO: 'sonar.coverage.jacoco.xmlReportPaths' is not defined. Using default locations: target/site/jacoco/jacoco.xml,target/site/jacoco-it/jacoco.xml,build/reports/jacoco/test/jacocoTestReport.xml
INFO: No report imported, no coverage information will be imported by JaCoCo XML Report Importer
INFO: Sensor JaCoCo XML Report Importer [jacoco] (done) | time=3ms
INFO: Sensor PL/SQL Sensor [plsql]
INFO: Sensor PL/SQL Sensor is restricted to changed files only
WARN: The Data Dictionary is not configured for the PLSQL analyzer, which prevents rule(s) S3641, S3921, S3618, S3651 from raising issues. See https://docs.sonarcloud.io/advanced-setup/languages/pl-sql/
INFO: 1 source files to be analyzed
INFO: 1/1 source files have been analyzed
INFO: Sensor PL/SQL Sensor [plsql] (done) | time=10176ms
INFO: Sensor IaC Docker Sensor [iac] (done) | time=163ms
INFO: Sensor TextAndSecretsSensor [text]
INFO: Sensor TextAndSecretsSensor is restricted to changed files only
INFO: Available processors: 2
INFO: Using 2 threads for analysis.
INFO: 1 source file to be analyzed
INFO: 1/1 source file has been analyzed
INFO: Sensor TextAndSecretsSensor [text] (done) | time=7033ms
INFO: ------------- Run sensors on project
INFO: Sensor Zero Coverage Sensor
INFO: Sensor Zero Coverage Sensor (done) | time=180ms
INFO: SCM Publisher SCM provider for this project is: git
INFO: SCM Publisher 1 source file to be analyzed
WARN: Shallow clone detected, no blame information will be provided. You can convert to non-shallow with 'git fetch --unshallow'.
INFO: SCM Publisher 0/1 source files have been analyzed (done) | time=4ms
WARN: Missing blame information for the following files:
WARN:   * src/oracle/packages/TD_MASTER.TOP_EXE_MANAGER_DDL.SQL
WARN: This may lead to missing/broken features in SonarCloud
INFO: CPD Executor Calculating CPD for 1 file
WARN: Too many duplication groups on file src/oracle/packages/TD_MASTER.TOP_EXE_MANAGER_DDL.SQL. Keep only the first 100 groups.
INFO: CPD Executor CPD calculation finished (done) | time=204ms
INFO: SCM writing changed lines
WARN: Could not find ref: master in refs/heads, refs/remotes/upstream or refs/remotes/origin
INFO: SCM writing changed lines (done) | time=28ms
INFO: Analysis report generated in 3570ms, dir size=2 MB
INFO: Analysis report compressed in 192ms, zip size=472 KB
INFO: Analysis report uploaded in 781ms
INFO: ANALYSIS SUCCESSFUL, you can find the results at: https://sonarcloud.io/dashboard?id=topdownprojetos_TopManager.V12&pullRequest=26653
INFO: Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
INFO: More about the report processing at https://sonarcloud.io/api/ce/task?id=AY9feTv24JcM2htt-tbP
INFO: Analysis total time: 56.535 s
INFO: ------------------------------------------------------------------------
INFO: EXECUTION SUCCESS
INFO: ------------------------------------------------------------------------
INFO: Total time: 1:25.631s
INFO: Final Memory: 206M/687M
INFO: ------------------------------------------------------------------------

Log of Sonar Run Code Analysis when it runs with a PR automated build validation using a pipeline with the “custom clone”

INFO: Pull request 26653 for merge into master from USING_SONAR
INFO: Preprocessing files...
INFO: 1 language detected in 185 preprocessed files
INFO: 10785 files ignored because of inclusion/exclusion patterns
INFO: 0 files ignored because of scm ignore settings
INFO: Loading plugins for detected languages
INFO: Load/download plugins
INFO: Load/download plugins (done) | time=50ms
INFO: Load project repositories
INFO: Load project repositories (done) | time=409ms
INFO: SCM collecting changed files in the branch
INFO: SCM collecting changed files in the branch (done) | time=549ms
INFO: Indexing files...
INFO: Project configuration:
INFO:   Included sources: src/oracle/packages/*, src/oracle/procedures/*, src/oracle/functions/*
INFO:   Excluded sources: **/build-wrapper-dump.json
INFO: 185 files indexed
INFO: Quality profile for plsql: Sonar way
INFO: ------------- Run sensors on module TopManager.V12
INFO: Load metrics repository
INFO: Load metrics repository (done) | time=358ms
INFO: Sensor cache enabled
INFO: Load sensor cache
INFO: Load sensor cache (404) | time=360ms
INFO: Sensor JaCoCo XML Report Importer [jacoco]
INFO: 'sonar.coverage.jacoco.xmlReportPaths' is not defined. Using default locations: target/site/jacoco/jacoco.xml,target/site/jacoco-it/jacoco.xml,build/reports/jacoco/test/jacocoTestReport.xml
INFO: No report imported, no coverage information will be imported by JaCoCo XML Report Importer
INFO: Sensor JaCoCo XML Report Importer [jacoco] (done) | time=0ms
INFO: Sensor PL/SQL Sensor [plsql]
INFO: Sensor PL/SQL Sensor is restricted to changed files only
WARN: The Data Dictionary is not configured for the PLSQL analyzer, which prevents rule(s) S3641, S3921, S3618, S3651 from raising issues. See https://docs.sonarcloud.io/advanced-setup/languages/pl-sql/
INFO: 0 source files to be analyzed
INFO: 0/0 source files have been analyzed
INFO: Sensor PL/SQL Sensor [plsql] (done) | time=797ms
INFO: Sensor IaC Docker Sensor [iac]
INFO: Sensor IaC Docker Sensor is restricted to changed files only
INFO: 0 source files to be analyzed
INFO: 0/0 source files have been analyzed
INFO: Sensor IaC Docker Sensor [iac] (done) | time=187ms
INFO: Sensor TextAndSecretsSensor [text]
INFO: Sensor TextAndSecretsSensor is restricted to changed files only
INFO: Available processors: 2
INFO: Using 2 threads for analysis.
INFO: Sensor TextAndSecretsSensor [text] (done) | time=782ms
INFO: ------------- Run sensors on project
INFO: Sensor Zero Coverage Sensor
INFO: Sensor Zero Coverage Sensor (done) | time=16ms
INFO: CPD Executor Calculating CPD for 0 files
INFO: CPD Executor CPD calculation finished (done) | time=0ms
INFO: SCM writing changed lines
INFO: SCM writing changed lines (done) | time=0ms
INFO: Analysis report generated in 3440ms, dir size=251 KB
INFO: Analysis report compressed in 94ms, zip size=83 KB
INFO: Analysis report uploaded in 573ms
INFO: ANALYSIS SUCCESSFUL, you can find the results at: https://sonarcloud.io/dashboard?id=topdownprojetos_TopManager.V12&pullRequest=26653
INFO: Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
INFO: More about the report processing at https://sonarcloud.io/api/ce/task?id=AY9fpdBd4JcM2htt-t56
INFO: Analysis total time: 46.173 s
INFO: ------------------------------------------------------------------------
INFO: EXECUTION SUCCESS
INFO: ------------------------------------------------------------------------
INFO: Total time: 1:16.618s
INFO: Final Memory: 206M/482M
INFO: ------------------------------------------------------------------------

[Solved]

So, In case someone gets this same problem, here is my solution:
I as able to get the PR by doing a custom command without tags/others refs + branches refs using the flag -t to the target branch ( instead of -m master in cases where the long live branch is master, because this flag returns all refs in repository ) and after that I do a fetch to the target branch + PR commit.

With that I gonna have in the local repo the current branch I want to analysis + the target branch, so with that SonarCloud can compare the files and do the analysis.

git remote add -t $(System.PullRequest.TargetBranchName) origin `
 "https://$(System.AccessToken)@dev.azure.com/topdownprojetos/Sistemas%20Topdown/_git/$(Build.Repository.Name)"
git fetch origin $(System.PullRequest.TargetBranchName) $(Build.SourceVersion) --progress --depth 1 --no-tags
git checkout --progress --force $(Build.SourceVersion)
git status
2 Likes

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