How to Scan after yarn build

The scan after the yarn build fails. Most likely I am using the sonar scanner with commands from MSbuild. Do you know of any tutorial for using SonarCloud with TypeScript?

Here is my yml file:

# Node.js
# Build a general Node.js project with npm.
# Add steps that analyze code, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/javascript

trigger:
- master

pool:
  vmImage: windows-latest

steps:
- checkout: self
  fetchDepth: 0
  
- task: NodeTool@0
  inputs:
    versionSpec: '20.11.x'
  displayName: 'Install Node.js'

- task: SonarCloudPrepare@1
  inputs:
    SonarCloud: '[Redacted]'
    organization: '[Redacted]'
    scannerMode: 'MSBuild'
    projectKey: '[Redacted]'
    projectName: '[Redacted]'
    extraProperties: |
      sonar.cs.xunit.reportsPaths=${Agent.TempDirectory}/**/XUnit.TestResults.xml 
      sonar.cs.opencover.reportsPaths=$(Build.SourcesDirectory)/coverage/coverage.opencover.xml

- task: CmdLine@2
  inputs:
    script: | 
        yarn install
        yarn build
  displayName: 'Yarn install and build'

- task: CmdLine@2
  inputs:
    script: | 
        npm run test:core
  displayName: '@[Redacted]/core unit test'
  
- task: CmdLine@2
  inputs:
    script: | 
        npm run test:cli
  displayName: '@[Redacted]/cli unit test'

- task: SonarCloudAnalyze@1
  inputs:
    jdkversion: 'JAVA_HOME_17_X64'

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

Template for a good new topic, formatted with Markdown:

  • ALM used: Azure DevOps
  • CI system used: Azure DevOps
  • Scanner command used when applicable (private details masked):
- task: SonarCloudAnalyze@1
  inputs:
    jdkversion: 'JAVA_HOME_17_X64'
  • Languages of the repository: TypeScript
  • Error observed (wrap logs/code around with triple quotes ``` for proper formatting)
##[error]21:37:02.63  The SonarScanner for MSBuild integration failed: SonarCloud was unable to collect the required information about your projects.

  • Steps to reproduce:
  1. Create a TypeScript Azure Devops repo
  2. Integrate with SonarSource
  3. Run the build by committing to a PR
  • Potential workaround: None

Do not share screenshots of logs – share the text itself (bonus points for being well-formatted)!

I found the tutorial and got it to work:

Using this I figured it out. Here is the updated yml file:

# Node.js
# Build a general Node.js project with npm.
# Add steps that analyze code, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/javascript

trigger:
- master

pool:
  vmImage: windows-latest

steps:
- checkout: self
  fetchDepth: 0
  
- task: NodeTool@0
  inputs:
    versionSpec: '20.11.x'
  displayName: 'Install Node.js'

- task: CmdLine@2
  inputs:
    script: | 
        yarn install
  displayName: 'Yarn install '

- task: SonarCloudPrepare@1
  inputs:
    SonarCloud: '[Redated]'
    organization: '[Redated]'
    scannerMode: 'CLI'
    projectKey: '[Redated]'
    projectName: '[Redated]'
    extraProperties: |
      sonar.cs.xunit.reportsPaths=${Agent.TempDirectory}/**/XUnit.TestResults.xml 
      sonar.cs.opencover.reportsPaths=$(Build.SourcesDirectory)/coverage/coverage.opencover.xml

- task: CmdLine@2
  inputs:
    script: | 
        yarn build
  displayName: 'Yarn build'

- task: CmdLine@2
  inputs:
    script: | 
        npm run test:core
  displayName: '@[Redated]/core unit test'
  
- task: CmdLine@2
  inputs:
    script: | 
        npm run test:cli
  displayName: '@[Redated]/cli unit test'

- task: SonarCloudAnalyze@1
  inputs:
    jdkversion: 'JAVA_HOME_17_X64'

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

I had to add a file called sonar-project.properties to the root repo directory:

sonar.projectKey=[Redated]
sonar.organization=[Redated]

# This is the name and version displayed in the SonarCloud UI.
sonar.projectName=[Redated]
sonar.projectVersion=1.0


# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
sonar.sources=.
sonar.javascript.lcov.reportPaths=./coverage/lcov.info

# Encoding of the source code. Default is default system encoding
sonar.sourceEncoding=UTF-8

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