This guide walks you through setting up Jenkins and SonarQube using Docker Compose to run code analysis on a Node.js application.
β Local setup β no external services required.
- Docker
- Any Git repository (e.g. MatheusIshiyama Repos)
Create a docker-compose.yml
in an empty folder:
version: '3'
services:
sonarqube:
image: sonarqube:lts
ports:
- 9000:9000
networks:
- mynetwork
jenkins:
image: jenkins/jenkins:lts
ports:
- 8080:8080
networks:
- mynetwork
networks:
mynetwork:
Run with:
docker compose up
- Go to
http://localhost:8080
- Use the unlock token from your terminal output
-
Click "Select plugins to install"
-
Click "None", then search and select:
git
pipeline
- Set Jenkins URL:
http://localhost:8080
- Visit
http://localhost:9000
- Login:
admin
| Password:admin
- Change password after first login
-
Go to Manage Jenkins > Manage Plugins > Available
-
Install:
SonarQube Scanner
NodeJS Plugin
- Manage Jenkins > Configure System
- Scroll to SonarQube Servers
- Add name:
SonarQube
, URL:http://sonarqube:9000
-
Manage Jenkins > Global Tool Configuration
-
Add:
- SonarQube Scanner (
SonarQubeScanner
) - Node.js (
NodeJs
)
- SonarQube Scanner (
-
In SonarQube go to: Administration > Configuration > Webhooks
-
Create a webhook:
- Name:
Jenkins
- URL:
http://jenkins:8080/sonarqube-webhook/
- Name:
In your Node.js app root:
sonar.projectKey=your-application
sonar.projectName=Your Application
sonar.sources=.
sonar.sourceEncoding=UTF-8
sonar.scm.disabled=true
- Click New Item β Name it β Select Pipeline β OK
Paste the following:
pipeline {
agent any
tools { nodejs "NodeJs" }
stages {
stage('Clone sources') {
steps {
git branch: 'main', url: 'https://github.com/MatheusIshiyama/BravanzinBot.git'
}
}
stage('SonarQube analysis') {
environment {
SCANNER_HOME = tool 'SonarQubeScanner'
}
steps {
withSonarQubeEnv('SonarQube') {
sh "${SCANNER_HOME}/bin/sonar-scanner"
}
}
}
}
}
Click Save, then Build Now.
- Go to your profile β My Account > Security
- Create token (e.g. name:
sonarqube-token
)
- Manage Jenkins > Configure System
- In SonarQube Servers, click
Add
under Authentication - Select
Secret text
β paste token β set ID (e.g.sonarqube-token
) - Choose that ID in Server authentication token
β Your Jenkins pipeline now integrates with SonarQube to analyze your Node.js code!