1. Java steps

Let us start with java install

  1. sudo apt-get update
  2. sudo apt-get upgrade
  3. sudo add-apt-repository ppa:webupd8team/java
  4. sudo apt-get update
  5. sudo apt-get install oracle-java8-installer -y— when the pop up comes, click OK and say YES to accept to install

2. Postgres Installation

sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" >> /etc/apt/sources.list.d/pgdg.list'

sudo wget -q https://www.postgresql.org/media/keys/ACCC4CF8.asc -O - | sudo apt-key add -

sudo apt-get -y install postgresql postgresql-contrib

sudo systemctl start postgresql

sudo systemctl enable postgresql


Change the password for postgres user by entering below command

  1. sudo passwd postgres
  2. enter as admin
  3. enter admin again for r-typing password
  4. su – postgres
  5. enter admin as password
  6. createuser sonar
  7. Switch to sql shell by entering:
    ALTER USER sonar WITH ENCRYPTED password 'password';
    CREATE DATABASE sonar OWNER sonar;
  8. type exit to come out of postgres user.

3. Now install SonarQube Web App

  1. sudo wget https://sonarsource.bintray.com/Distribution/sonarqube/sonarqube-7.2.1.zip
  2. sudo apt-get -y install unzip
  3. sudo unzip sonarqube-7.2.1.zip -d /opt
  4. sudo mv /opt/ sonarqube-7.2.1 /opt/sonarqube
  5. sudo nano /opt/sonarqube/conf/sonar.properties
  6. uncomment the below lines by removing # and add values highlighted:
  7. Next, uncomment:
  8. sudo vi /etc/systemd/system/sonar.service
  9. add the below code in bold color:
    Description=SonarQube service
    After=syslog.target network.target
    Type=forkingExecStart=/opt/sonarqube/bin/linux-x86-64/sonar.sh start
    ExecStop=/opt/sonarqube/bin/linux-x86-64/sonar.sh stopUser=root
  10. create a new group and user for sonar. (/opt/sonarqube is sonar installation directory in my case)
  11. sudo groupadd sonar
  12. sudo useradd -c "Sonar System User" -d /opt/sonarqube -g sonar -s /bin/bash sonar
  13. make new user owner of sonar installation directory and
  14. sudo chown -R sonar:sonar /opt/sonarqube
  15. specify this new user in /opt/sonarqube/bin/linux-x86-64/sonar.sh by finding RUN_AS_USER entry, uncomment it and assign newly created user:
  16. sudo systemctl enable sonar
  17. sudo systemctl start sonar
  18. sudo systemctl status sonar
  19. type q now to come out of this mode.
  20. now access sonarQube UI by going to browser and enter public dns name with port 9000
  21. now to go to browser –> http://your_SonarQube_publicdns_name:9000/


4. Integrating SonarQube with Jenkins

Pre-requisites: Make sure SonarQube is up and running and do the below steps:

Make sure Sonarqube plug-in installed in Jenkins

1. You need to login to SonarQube using admin/admin and click on administration, security, users, click on Tokens, under generate token.

give some value for token name and click on generate. Copy the token.

  1. After installing SonarQube successfully, login to Jenkins. Manage Jenkins –> Configure System –> SonarQube installation

enter name, URL, paste the token you copied from step #1

  1. Click on Enable injection of Sonarqube server configuration.
  2. Save.
  3. Click on free style job configuration. click on prepare Sonarqube scanner  environment
  4. enter maven goal as clean install sonar:sonar
  5. click on save and build the job.