Setting up Jenkins with SonarQube(with DB) on Windows for Source Code Review or SAST for GitHub Repos — Ondemand Scan
Pre-Requisites:
Installed Java — any version
Windows Machine — any version
MS SQL Server
MS SSMS — (SQL Server Management Studio)
Visual Studio — for testing connection to DB
SonarQube
Jenkins
Sonar Scanner Plugin in Jenkins
Internet connection — high speed preferred
P.S: One by one we install and test every Application and finally we’d be able to setup OnDemand Source Code Review using SonarQube(with DB)+Jenkins+Git
Important: Make sure to download latest version of all the Appliactions used in this article.
Blueprint of Architecture:
Explanation: We are setting up integration framework on a Windows machine in which a successful Jenkins job would download repo from git and would run sonarqube for code review, & output would be shown on SonarQube’s dashboard in browser.
Installation of Jenkins:
Download zip file containing Microsoft Installer. Unzip and run the installer. click
Installation of Microsoft SQL Server:
Download & Install MSSQL Express click
Go for Express edition as it is free.
Installation of Microsoft SQL Server Management Studio:
Search for SQLManagement Studio (SSMS), i went for 64-bit English version
Installation of SonarQube:
Download latest version of SonarQube. click
Server name from SSMS:
Configuring MSSQL using MS-SSMS:
create new db Sonar: In Databases,
- General tab, Create new database, and name it Sonar.
- Options tab, set collation as SQL_Latin1_General_CP1_CS_AS
create new login SonarQ: In Security > Login
- In General tab, Create new Login SonarQ & <password> with SQL Server Authentication
- In Server Roles tab, select public & sysadmin as server roles.
- In User Mapping tab, select Sonar
enable SQL Login:
- Right Click and select Properties
2. In Security tab, select SQL Server and Windows Authentication
Now, In order to make all changes in place, make sure to restart SQL Server service before attempting login via SQL Server Authentication else you would get 18456 error.
- Go to Administrative Tools > Services
2. SQL Server service Right Click and select Restart
3. Select SQL Server Authentication, insert user name SonarQ & <password>
Install Visual Studio:
Install Visual Studio to check data connectivity
Check Connection 1:
Check Connection 2: In case if server name does not appears then copy and paste server name. You can copy server name from SSMS.
More Config for SonarQube Integration:
- Open SQL Server Configuration Manager
2. Right click and select enable
3. Double click and Properties open
Restart SQL Server Service for changes to take effect.
Click Apply, and now it’s time to configure and run SonarQube.
Starting SonarQube server:
Before starting SonarQube server, make below mentioned changes in: C:\Users\Enterprise-Security\Downloads\sonarqube-7.7\sonarqube-7.7\conf
Insert server name in highlighted portion.
Or, below config would also work.
C:\Users\Enterprise-Security\Downloads\sonarqube-7.4\sonarqube-7.4\bin\windows-x86–64\
- StartNTService.bat
- StartSonar.bat
Setting up Jenkins:
Download & Install Jenkins from msi installer.
After successful installation localhost:8080 would have jenkins dashboard.
- Double click
2. Use command, and login to console then password.
notepad C:\Program Files (x86)\Jenkins\secrets\initialAdminPassword
Start/Stop jenkins service from services.
Browse available plugins & search for Sonar
Configure Sonar Scanner Plugin:
Follow the link & Generate Token named Jenkins.
Copy Token & paste it in Sonar Scanner Plugin Config.
Configuring Jenkins for Scanning:
Install Git Plugin for Integration
Install Git Parameter Plugin for Tags selection
Browse to Manage Jenkins,
Configure other settings as per your requirement.
- Setup up SonarQube URL for output to be shown in dashboard
2. Setup Secret Text based authentication
3. Insert Jenkins URL, in this case it is locally hosted.
4. Setting up e-mail notifiction
In Global tools configurations, we setup Java configs,
Setting up Java Config,
Setting up Jenkins Job for Automated Code Review:
- Insert your project URL
2. Provide repo URL & select/add credentials for Git (in this case username/password was used)
3. Analysis properties may vary with different projects.
4. Enter e-mail for receiving notification and click save.
5. It’s time to run Job & check outcome.
6. Goto SonarQube dashboard and analyse.
P.S: I succeed by this process as Code Review is done monthly and every commit would create overhead for Devlopers & Security Team to manage, hence on-demand method is used. before rolling out live code, on-demand assessment is carried out.