zero new lines while I do sonarscan on pull request using azure pipeline for my dot net code

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>- script: |
git config --global http.https://dev.azure.com/<company>/.extraheader "AUTHORIZATION: bearer $(System.AccessToken)"
# Now fetch the PR source branch using the token
git fetch origin $(System.PullRequest.SourceBranch):$(System.PullRequest.SourceBranch)
git checkout $(System.PullRequest.SourceBranch)
displayName: 'Fetch and Checkout PR Source Branch'
env:
# This exposes the system access token to the script
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
- script: |
git checkout $(System.PullRequest.SourceBranch)
displayName: 'Checkout PR Source Branch'
- task: DotNetCoreCLI@2
displayName: New Manifest for tool
inputs:
command: custom
custom: 'new '
arguments: tool-manifest
- task: PowerShell@2
displayName: Set the prereleaseVersionNumber variable value
inputs:
targetType: 'inline'
script: |
[string] $dateTime = (Get-Date -Format 'yyyyMMddTHHmmss')
[string] $prereleaseVersionNumber = "$(stableVersionNumber)-$(Build.SourceVersion)"
Write-Host "Setting the prerelease version number variable to '$prereleaseVersionNumber'."
Write-Host "##vso[task.setvariable variable=prereleaseVersionNumber]$prereleaseVersionNumber"
- task: PowerShell@2
displayName: Set the versionNumber to the stable or prerelease version number based on if the 'main' branch is being built or not
inputs:
targetType: 'inline'
script: |
[bool] $isMainBranch = $$(isMainBranch)
[string] $versionNumber = "$(prereleaseVersionNumber)"
if ($isMainBranch)
{
$versionNumber = "$(stableVersionNumber)"
}
Write-Host "Setting the version number to use to '$versionNumber'."
Write-Host "##vso[task.setvariable variable=versionNumber]$versionNumber"
- task: PowerShell@2
displayName: Set the name of the build (i.e. the Build.BuildNumber)
inputs:
targetType: 'inline'
script: |
[string] $buildName = "$(versionNumber)_$(Build.SourceBranchName)"
Write-Host "Setting the name of the build to '$buildName'."
Write-Host "##vso[build.updatebuildnumber]$buildName"
- task: NuGetToolInstaller@1
displayName: 'Install NuGet 5.8'
inputs:
versionSpec: '5.8.x'
- task: NuGetCommand@2
displayName: 'Restore packages using NuGet'
inputs:
restoreSolution: '**/*.csproj'
- task: UseDotNet@2
displayName: Use .NET 6.0
inputs:
packageType: 'sdk'
version: '6.0.x'
- task: DotNetCoreCLI@2
displayName: 'Add Coverlet.msbuild package'
inputs:
command: 'custom'
custom: 'add'
projects: '$(Build.SourcesDirectory)/Virtue/Virtue.API/Virtue.API.csproj'
arguments: 'package coverlet.msbuild'
- task: DotNetCoreCLI@2
displayName: 'dotnet restore Virtue.API'
inputs:
command: 'restore'
projects: '$(Build.SourcesDirectory)/Virtue/Virtue.API/Virtue.API.csproj'
includeNuGetOrg: true
noCache: true
- task: SonarCloudPrepare@1
inputs:
SonarCloud: 'SonarCloud Service Connection'
organization: '<company_name>'
scannerMode: 'MSBuild'
projectKey: 'dotnet'
projectName: 'Dotnet'
extraProperties: |
sonar.projectBaseDir=$(Build.SourcesDirectory)
sonar.exclusions=**/README.md,**/obj/**,**/*.dll
sonar.inclusions=**/*.csproj
sonar.cs.vscoveragexml.reportsPaths=$(Build.SourcesDirectory)/**/coverage.xml
sonar.cs.opencover.reportsPaths=$(Build.SourcesDirectory)/**/coverage.opencover.xml
sonar.cs.vstest.reportsPaths=$(Agent.TempDirectory)/*.trx
sonar.pullrequest.key=$(System.PullRequest.PullRequestId)
sonar.pullrequest.branch=$(System.PullRequest.SourceBranch)
sonar.pullrequest.base=$(System.PullRequest.TargetBranch)
- task: DotNetCoreCLI@2
inputs:
command: 'build'
projects: '**/*.csproj'
arguments: '--configuration $(buildConfiguration)'
- task: DotNetCoreCLI@2
displayName: 'Test ...'
inputs:
command: test
projects: '**/*Tests/*.csproj'
arguments: '--configuration $(BuildConfiguration) /p:CollectCoverage=true /p:CoverletOutputFormat=opencover --logger trx'
testRunTitle: 'dotnet test'
- task: PublishCodeCoverageResults@1
inputs:
codeCoverageTool: 'Cobertura'
summaryFileLocation: '$(Build.SourcesDirectory)/**/coverage.opencover.xml'
reportDirectory: '$(Build.SourcesDirectory)/**/coverage/'
- script: |
dotnet tool install -g dotnet-reportgenerator-globaltool
reportgenerator -reports:$(Build.SourcesDirectory)/**/coverage.opencover.xml -targetdir:$(Build.SourcesDirectory)/CoverageReport -reporttypes:"HtmlInline;Cobertura"
displayName: 'Generate Coverage Report'
- task: PublishTestResults@2
displayName: "Publish Test Results"
inputs:
testResultsFormat: VSTest
testResultsFiles: "$(Build.SourcesDirectory)/**.*trx"
mergeTestResults: true
condition: succeededOrFailed()
- task: SonarCloudAnalyze@1
inputs:
sonar.analysis.level: 'DOTNET'
- task: SonarCloudPublish@1
inputs:
pollingTimeoutSec: '300'
</code>
<code>- script: | git config --global http.https://dev.azure.com/<company>/.extraheader "AUTHORIZATION: bearer $(System.AccessToken)" # Now fetch the PR source branch using the token git fetch origin $(System.PullRequest.SourceBranch):$(System.PullRequest.SourceBranch) git checkout $(System.PullRequest.SourceBranch) displayName: 'Fetch and Checkout PR Source Branch' env: # This exposes the system access token to the script SYSTEM_ACCESSTOKEN: $(System.AccessToken) - script: | git checkout $(System.PullRequest.SourceBranch) displayName: 'Checkout PR Source Branch' - task: DotNetCoreCLI@2 displayName: New Manifest for tool inputs: command: custom custom: 'new ' arguments: tool-manifest - task: PowerShell@2 displayName: Set the prereleaseVersionNumber variable value inputs: targetType: 'inline' script: | [string] $dateTime = (Get-Date -Format 'yyyyMMddTHHmmss') [string] $prereleaseVersionNumber = "$(stableVersionNumber)-$(Build.SourceVersion)" Write-Host "Setting the prerelease version number variable to '$prereleaseVersionNumber'." Write-Host "##vso[task.setvariable variable=prereleaseVersionNumber]$prereleaseVersionNumber" - task: PowerShell@2 displayName: Set the versionNumber to the stable or prerelease version number based on if the 'main' branch is being built or not inputs: targetType: 'inline' script: | [bool] $isMainBranch = $$(isMainBranch) [string] $versionNumber = "$(prereleaseVersionNumber)" if ($isMainBranch) { $versionNumber = "$(stableVersionNumber)" } Write-Host "Setting the version number to use to '$versionNumber'." Write-Host "##vso[task.setvariable variable=versionNumber]$versionNumber" - task: PowerShell@2 displayName: Set the name of the build (i.e. the Build.BuildNumber) inputs: targetType: 'inline' script: | [string] $buildName = "$(versionNumber)_$(Build.SourceBranchName)" Write-Host "Setting the name of the build to '$buildName'." Write-Host "##vso[build.updatebuildnumber]$buildName" - task: NuGetToolInstaller@1 displayName: 'Install NuGet 5.8' inputs: versionSpec: '5.8.x' - task: NuGetCommand@2 displayName: 'Restore packages using NuGet' inputs: restoreSolution: '**/*.csproj' - task: UseDotNet@2 displayName: Use .NET 6.0 inputs: packageType: 'sdk' version: '6.0.x' - task: DotNetCoreCLI@2 displayName: 'Add Coverlet.msbuild package' inputs: command: 'custom' custom: 'add' projects: '$(Build.SourcesDirectory)/Virtue/Virtue.API/Virtue.API.csproj' arguments: 'package coverlet.msbuild' - task: DotNetCoreCLI@2 displayName: 'dotnet restore Virtue.API' inputs: command: 'restore' projects: '$(Build.SourcesDirectory)/Virtue/Virtue.API/Virtue.API.csproj' includeNuGetOrg: true noCache: true - task: SonarCloudPrepare@1 inputs: SonarCloud: 'SonarCloud Service Connection' organization: '<company_name>' scannerMode: 'MSBuild' projectKey: 'dotnet' projectName: 'Dotnet' extraProperties: | sonar.projectBaseDir=$(Build.SourcesDirectory) sonar.exclusions=**/README.md,**/obj/**,**/*.dll sonar.inclusions=**/*.csproj sonar.cs.vscoveragexml.reportsPaths=$(Build.SourcesDirectory)/**/coverage.xml sonar.cs.opencover.reportsPaths=$(Build.SourcesDirectory)/**/coverage.opencover.xml sonar.cs.vstest.reportsPaths=$(Agent.TempDirectory)/*.trx sonar.pullrequest.key=$(System.PullRequest.PullRequestId) sonar.pullrequest.branch=$(System.PullRequest.SourceBranch) sonar.pullrequest.base=$(System.PullRequest.TargetBranch) - task: DotNetCoreCLI@2 inputs: command: 'build' projects: '**/*.csproj' arguments: '--configuration $(buildConfiguration)' - task: DotNetCoreCLI@2 displayName: 'Test ...' inputs: command: test projects: '**/*Tests/*.csproj' arguments: '--configuration $(BuildConfiguration) /p:CollectCoverage=true /p:CoverletOutputFormat=opencover --logger trx' testRunTitle: 'dotnet test' - task: PublishCodeCoverageResults@1 inputs: codeCoverageTool: 'Cobertura' summaryFileLocation: '$(Build.SourcesDirectory)/**/coverage.opencover.xml' reportDirectory: '$(Build.SourcesDirectory)/**/coverage/' - script: | dotnet tool install -g dotnet-reportgenerator-globaltool reportgenerator -reports:$(Build.SourcesDirectory)/**/coverage.opencover.xml -targetdir:$(Build.SourcesDirectory)/CoverageReport -reporttypes:"HtmlInline;Cobertura" displayName: 'Generate Coverage Report' - task: PublishTestResults@2 displayName: "Publish Test Results" inputs: testResultsFormat: VSTest testResultsFiles: "$(Build.SourcesDirectory)/**.*trx" mergeTestResults: true condition: succeededOrFailed() - task: SonarCloudAnalyze@1 inputs: sonar.analysis.level: 'DOTNET' - task: SonarCloudPublish@1 inputs: pollingTimeoutSec: '300' </code>
- script: |   
    git config --global http.https://dev.azure.com/<company>/.extraheader "AUTHORIZATION: bearer $(System.AccessToken)"
    
    # Now fetch the PR source branch using the token
    git fetch origin $(System.PullRequest.SourceBranch):$(System.PullRequest.SourceBranch)
    git checkout $(System.PullRequest.SourceBranch)
  displayName: 'Fetch and Checkout PR Source Branch'
  env:
    # This exposes the system access token to the script
    SYSTEM_ACCESSTOKEN: $(System.AccessToken)

- script: |
    git checkout $(System.PullRequest.SourceBranch)
  displayName: 'Checkout PR Source Branch'

- task: DotNetCoreCLI@2
  displayName: New Manifest for tool
  inputs:
    command: custom
    custom: 'new '
    arguments: tool-manifest



- task: PowerShell@2
  displayName: Set the prereleaseVersionNumber variable value
  inputs:
    targetType: 'inline'
    script: |
      [string] $dateTime = (Get-Date -Format 'yyyyMMddTHHmmss')
      [string] $prereleaseVersionNumber = "$(stableVersionNumber)-$(Build.SourceVersion)"
      Write-Host "Setting the prerelease version number variable to '$prereleaseVersionNumber'."
      Write-Host "##vso[task.setvariable variable=prereleaseVersionNumber]$prereleaseVersionNumber"

- task: PowerShell@2
  displayName: Set the versionNumber to the stable or prerelease version number based on if the 'main' branch is being built or not
  inputs:
    targetType: 'inline'
    script: |
      [bool] $isMainBranch = $$(isMainBranch)
      [string] $versionNumber = "$(prereleaseVersionNumber)"
      if ($isMainBranch)
      {
        $versionNumber = "$(stableVersionNumber)"
      }
      Write-Host "Setting the version number to use to '$versionNumber'."
      Write-Host "##vso[task.setvariable variable=versionNumber]$versionNumber"

- task: PowerShell@2
  displayName: Set the name of the build (i.e. the Build.BuildNumber)
  inputs:
    targetType: 'inline'
    script: |
      [string] $buildName = "$(versionNumber)_$(Build.SourceBranchName)"
      Write-Host "Setting the name of the build to '$buildName'."
      Write-Host "##vso[build.updatebuildnumber]$buildName"
- task: NuGetToolInstaller@1
  displayName: 'Install NuGet 5.8'
  inputs:
    versionSpec: '5.8.x'
    
- task: NuGetCommand@2
  displayName: 'Restore packages using NuGet'
  inputs:
    restoreSolution: '**/*.csproj'
     
- task: UseDotNet@2
  displayName: Use .NET 6.0
  inputs:
    packageType: 'sdk'
    version: '6.0.x'


- task: DotNetCoreCLI@2
  displayName: 'Add Coverlet.msbuild package'
  inputs:
    command: 'custom'
    custom: 'add'
    projects: '$(Build.SourcesDirectory)/Virtue/Virtue.API/Virtue.API.csproj'
    arguments: 'package coverlet.msbuild'
  

- task: DotNetCoreCLI@2
  displayName: 'dotnet restore Virtue.API'
  inputs:
    command: 'restore'
    projects: '$(Build.SourcesDirectory)/Virtue/Virtue.API/Virtue.API.csproj'
    includeNuGetOrg: true
    noCache: true

- task: SonarCloudPrepare@1
  inputs:
    SonarCloud: 'SonarCloud Service Connection'
    organization: '<company_name>'
    scannerMode: 'MSBuild'
    projectKey: 'dotnet'
    projectName: 'Dotnet'
    extraProperties: |
      sonar.projectBaseDir=$(Build.SourcesDirectory)
      sonar.exclusions=**/README.md,**/obj/**,**/*.dll
      sonar.inclusions=**/*.csproj
      sonar.cs.vscoveragexml.reportsPaths=$(Build.SourcesDirectory)/**/coverage.xml
      sonar.cs.opencover.reportsPaths=$(Build.SourcesDirectory)/**/coverage.opencover.xml
      sonar.cs.vstest.reportsPaths=$(Agent.TempDirectory)/*.trx
      sonar.pullrequest.key=$(System.PullRequest.PullRequestId)
      sonar.pullrequest.branch=$(System.PullRequest.SourceBranch)
      sonar.pullrequest.base=$(System.PullRequest.TargetBranch)


- task: DotNetCoreCLI@2
  inputs:
    command: 'build'
    projects: '**/*.csproj'
    arguments: '--configuration $(buildConfiguration)'


- task: DotNetCoreCLI@2
  displayName: 'Test ...'
  inputs:
    command: test
    projects: '**/*Tests/*.csproj'
    arguments: '--configuration $(BuildConfiguration) /p:CollectCoverage=true /p:CoverletOutputFormat=opencover --logger trx'
    testRunTitle: 'dotnet test'

- task: PublishCodeCoverageResults@1
  inputs:
    codeCoverageTool: 'Cobertura'
    summaryFileLocation: '$(Build.SourcesDirectory)/**/coverage.opencover.xml'
    reportDirectory: '$(Build.SourcesDirectory)/**/coverage/'

- script: |
    dotnet tool install -g dotnet-reportgenerator-globaltool
    reportgenerator -reports:$(Build.SourcesDirectory)/**/coverage.opencover.xml -targetdir:$(Build.SourcesDirectory)/CoverageReport -reporttypes:"HtmlInline;Cobertura"
  displayName: 'Generate Coverage Report'
  
- task: PublishTestResults@2
  displayName: "Publish Test Results"
  inputs:
    testResultsFormat: VSTest
    testResultsFiles: "$(Build.SourcesDirectory)/**.*trx"
    mergeTestResults: true
    condition: succeededOrFailed()

- task: SonarCloudAnalyze@1
  inputs:
    sonar.analysis.level: 'DOTNET'

- task: SonarCloudPublish@1
  inputs:
    pollingTimeoutSec: '300'

Why on pull request, it is not taking new lines from my feature branch. I could see zero coverage and no new lines. Please help me. It is on high priority.

I tried many ways but no luck. I would like to analyse new lines of code using pull request that triggers my azure pipeline

New contributor

Sneha Reddy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật