<img alt="" src="https://secure.leadforensics.com/150446.png " style="display:none;">
Go to top icon

Integration of AWS CodeCommit, Jenkins and SonarQube

Chetan Zade Oct 19, 2016

Jenkins AWS CodeCommit SonarQube

What is AWS Codecommit?

AWS CodeCommit is a version control service hosted by Amazon Web Services that you can use to privately store and manage assets in the cloud. It is secure, highly scalable, managed source control service that hosts private Git repositories. AWS CodeCommit eliminates the need for you to manage your own source control system or worry about scaling its infrastructure.

What is Jenkins?

Jenkins is an open source automation server written in Java. Jenkins helps automating the non-human part of the whole software development process, with now common things like Continuous Integration, but by further empowering teams to implement the technical part of a Continuous Delivery. It is a server-based system running in a servlet container such as Apache Tomcat.

What is SonarQube?

Sonar is an open source platform used by development teams to manage source code quality. Sonar has been developed with a main objective in mind: make code quality management accessible to everyone with minimal effort. It provides code analysers, reporting tools, defects hunting modules and TimeMachine as core functionality.

Pre-requisite:

  1. AWS CodeCommit Repository

Steps to install Jenkins:
Launch an instance with minimum configuration of t2.medium if SonarQube and Jenkins are on same instance

  1. Login to an instance (Root user is preferred).
  2. Check Java version. If Java is not present, install Java.

(Command:java -version)

  1. Install Jenkins. Hit the following commands:
    1. sudowget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.repo
    2. sudo rpm --import https://jenkins-ci.org/redhat/jenkins-ci.org.key
    3. sudo yum install Jenkins
  2. Start Jenkins.
    Command: service jenkins start
    1. In browser, open http://<PUBLIC DNS/IP>:8080
    2. On instance, enter the command
      cat /var/lib/jenkins/secrets/initialAdminPassword
    3. Install suggested plugins
    4. Create admin user, save and finish
    5. Start using Jenkins
  3. Select Manage Jenkins and Configure Global Security
  4. Select the Enable Security check box.
  5. Under Security Realm, select the Jenkins’ own user database radio button.
  6. Clear the Allow users to sign up check box.
  7. Under Authorization, select the Logged-in users can do anything radio button
  8. Manage Jenkins -> Manage Plugins. Check following plugins. If not available, install it
    1. Git plugin
    2. Git Client plugin
    3. SonarQube plugin

Steps to install SonarQube:

  1. Commands to install SonarQube are as follow:
    1. cd /opt/
    2. wget https://sonarsource.bintray.com/Distribution/SonarQube/SonarQube-5.4.zip
    3. unzip SonarQube-5.4.zip
    4. yum install mysql-server
    5. /etc/init.d/mysqld start
    6. vi SonarQube-5.4/conf/sonar.properties and uncomment following lines :
      1. sonar.jdbc.username=sonar
      2. sonar.jdbc.password=sonar
      3. sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance
      4. sonar.web.port=9000

             g. mysql

  1. create database sonar;
  2. CREATE USER 'sonar'@'localhost' IDENTIFIED BY 'sonar';
  3. GRANT ALL PRIVILEGES ON sonar.* TO 'sonar'@'localhost';
  4. FLUSH PRIVILEGES;
  5. exit

            h. cd SonarQube-5.4

            i. bin/linux-x86-64/sonar.sh start

  1. Go to link : http://<PUBLIC-DNS/IP>:9000
    1. Login (Username & Password = admin)
    2. Go to Administration -> System -> update centre
      1. Check for the required plugins and install them
      2. Restart SonarQube after installation of plugin

Configuration of Jenkins and AWS Codecommit:

  1. Enter following commands :
    1. yum install git
    2. yum install aws-cli
    3. cd ~jenkins
    4. sudo -u jenkinsaws configure
      1. Enter Access key ID of the AWS account user and hit enter
      2. Enter Secret key ID of the AWS account user and hit enter
      3. Default region name (print the same value as shown)- us-east-1
      4. Default output format (print the same value as shown) –json

           e. sudo -u jenkins git config --global credential.helper '!awscodecommit credential-helper $@'

           f. sudo -u jenkins git config --global credential.useHttpPath true

           g. sudo -u jenkins git config --global user.email "<EMAIL ID OF THE USER>"

           h. sudo -u jenkins git config --global user.name "<USERNAME OF THE USER>"

  1. Go to admin panel of Jenkins
  2. Click on New Item -> Enter name of project -> select Freestyle Project -> Ok
  3. In Source management -> select Git -> Enter the https URL of aws codecommit -> Save

Configuration of Jenkins and SonarQube:

  1. On Instance, execute the following commands :
    1. cd /opt/
    2. vi sonar.properties and paste following lines :

sonar.projectKey=<PROJECT KEY>

sonar.projectName=<PROJECT NAME>

sonar.projectVersion=1.0

sonar.language=php

sonar.sourceEncoding=UTF-8

sonar.sources=.

             c. chmod 660 sonar.properties

  1. Go to SonarQube Dashboard
    1. Administration -> In Security, select Users ->  In Admin user, Click on Token
    2. Generate token
    3. Copy the token
  2. Go to Jenkins Dashboard
  3. Manage Jenkins -> Global Tool Configuration -> SonarQube Scanner -> Add SonarQube Scanner
    1. Name : SonarQube
    2. Version : SonarQube scanner 2.8
    3. Check install automatically checkbox
  4. Manage Jenkins ->configuration Systemà In SonarQube server, click add SonarQube and add parameters as :
    1. Name : SonarQube
    2. Server URL : http://<PUBLIC DNS/IP OF SONARQUBE>:9000
    3. Server version : 5.3 or higher
    4. Server authentication token : Paste the token generated from SonarQube
    5. Click on Advanced
    6. Database URL : jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance
    7. Database login : sonar
    8. Database password : sonar
    9. Apply and Save
  5. Select created project -> click on configure
    1. In Build section, click on Add build Step and select Execute SonarQube scanner
    2. Configure as follow :
      1. SonarQube Installation : SonarQube
      2. Path to project properties : /opt/sonar.properties

Note: To Avoid this following error follow the steps:
Error:The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
Steps:

  1. vi /etc/my.cnf
  2. Under [mysqld], paste the following line:
    max_allowed_packet=256M
  3. service mysqld restart
  4. service jenkins restart
  5. /opt/SonarQube-5.4/bin/linux-x86-64/sonar.sh restart

Source:

https://en.wikipedia.org/wiki/Jenkins_(software)

http://www.methodsandtools.com/tools/tools.php?sonar

http://docs.aws.amazon.com/codecommit/latest/userguide/welcome.html

e-Zest is a leading digital innovation partner for enterprises and technology companies that utilizes emerging technologies for creating engaging customers experiences. Being a customer-focused and technology-driven company, it always helps clients in crafting holistic business value for their software development efforts. It offers software development and consulting services for cloud computing, enterprise mobility, big data and analytics, user experience and digital commerce.