Forum Discussion

vijit-devops's avatar
vijit-devops
Copper Contributor
Aug 23, 2023

How to integrate sonarqube for react js in azure devops pipeline ?

Hi Team,

I have added sonarqube stage in my yaml file for React js application.

But it is not showing in sonarqube, service connection between SQ and ADO is done and it is working for maven builds.

 

Please let me know the exact document or steps for react js pipeline as well.

 

- task: SonarQubePrepare@5
  inputs:
    SonarQube: '<my service connection>'
    scannerMode: 'CLI'
    configMode: 'file'
    configFile: 'sonar-project.properties'
    extraProperties: |
     sonar.javascript.lcov.reportPaths=coverage/lcov-report/lcov.info
  displayName: 'Prepare SonarQube Analysis'
 
sonar-project.properties 
 
sonar.projectKey=com.cat.rcc:rcc-UI
sonar.projectName=UI App
sonar.sources=src
sonar.exclusions=**/*.test.js
sonar.tests=src
sonar.test.inclusions=**/*.test.js
sonar.javascript.lcov.reportPaths=coverage/lcov-report/lcov.info
sonar.host.url=https://sonarqube.halt.com
sonar.login= <what will be value ?>
 
Please help on this

1 Reply

  • This this to integrate SonarQube for React.js:

     

    1. Use the Correct Authentication Token
    In your sonar-project.properties, the sonar.login value should be a SonarQube user token.
    •    Go to your SonarQube instance.
    •    Navigate to My Account > Security > Generate Tokens.
    •    Use this token as the value for sonar.login.
     

    Store token as a secret variable in Azure DevOps:

     

    sonar.login=$(SONARQUBE_TOKEN)



    2. Ensure the Analysis Is Triggered
    You need to include the full SonarQube pipeline sequence:

    - task: SonarQubePrepare@5
      inputs:
        SonarQube: '<your service connection>'
        scannerMode: 'CLI'
        configMode: 'file'
        configFile: 'sonar-project.properties'
        extraProperties: |
          sonar.javascript.lcov.reportPaths=coverage/lcov-report/lcov.info
    
    - script: |
        npm install
        npm run test -- --coverage
        sonar-scanner
      displayName: 'Run Tests and Sonar Scanner'
    
    - task: SonarQubePublish@5
      inputs:
        pollingTimeoutSec: '300'
      displayName: 'Publish SonarQube Results'


    3. Validate sonar-project.properties

    sonar.projectKey=com.cat.rcc:rcc-UI
    sonar.projectName=UI App
    sonar.sources=src
    sonar.exclusions=**/*.test.js
    sonar.tests=src
    sonar.test.inclusions=**/*.test.js
    sonar.javascript.lcov.reportPaths=coverage/lcov-report/lcov.info
    sonar.host.url=https://sonarqube.halt.com
    sonar.login=<your token or $(SONARQUBE_TOKEN)>

Resources