SonarQube Integration for Node JS Project using GitLab

In this article we are going to cover SonarQube integration for Node JS Project using GitLab CI/CD.


  • Ubuntu Server 20.04/18.04/16.04 LTS
  • SSH access with sudo privileges

Please find below articles to Install Gitlab-Runner

How to Install GitLab Runner on Ubuntu 20.04 LTS

#1:Install nodejs on Ubuntu 20.04 LTS

Update your system packages:

sudo apt-get update

Install nodejs on GitLab Runner Instance

curl -sL | sudo -E bash - 
sudo apt-get install -y nodejs

To verify nodejs version 

node -v

#2:Download and Install Sonar Scanner on Linux

Download the Sonarqube scanner package and move it to the OPT directory.

Make a directory /downloads/sonarqube

mkdir /downloads/sonarqube -p

You need to inside this  /downloads/sonarqube directory 

cd /downloads/sonarqube

Download  sonar-scanner using wget command:


Install unzip if you don’t have

sudo apt install unzip

Unzip the file:


Move to /opt directory

mv sonar-scanner- /opt/sonar-scanner

Edit the file using below command:

vi /opt/sonar-scanner/conf/

Add this line in this file:

create a file to automate the required environment variables configuration

vi /etc/profile.d/

Add this lines in this file

export PATH="$PATH:/opt/sonar-scanner/bin"

Use the source command to add the sonar scanner command to the PATH variable:

source /etc/profile.d/

To verify version of sonar-scanner

sonar-scanner -v

#3:Create in your repository

Create a file in your repository with the name and add this lines into it


#4:Add SonarQube variables in your gitlab repository

SONAR_HOST_URL   : <<sonarqube-url>>
SONAR_LOGIN           : <<sonarqube username>>
SONAR_PASSWORD: <<sonarqube password>> 

#5:SonarQube integration for Node JS Project using GitLab

Create a .gitlab-ci.yml file in your repository and paste the below code into it.

    name: sonarsource/sonar-scanner-cli:latest
    entrypoint: [""]
    SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar"  # Defines the location of the analysis task cache
    GIT_DEPTH: "0"  # Tells git to fetch all the branches of the project, required by the analysis task
    key: "${CI_JOB_NAME}"
      - .sonar/cache
    - sonar-scanner -X -Dsonar.sources=.$SONAR_HOST_URL -Dsonar.login=$SONAR_LOGIN -Dsonar.password=$SONAR_PASSWORD
    - main # or the name of your main branch


We have covered SonarQube integration for Node JS Project using GitLab CI/CD.


SonarQube official page for GitLab CI/CD

Shweta Mamidwar

I am Shweta Mamidwar working as a Intern in Product Company. Likes to share knowledge.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Share via
Copy link
Powered by Social Snap