0% found this document useful (0 votes)
277 views

C I-Jenkins

The document describes setting up a continuous integration workflow using Jenkins, SonarQube, and Nexus. It involves creating EC2 instances for Jenkins, SonarQube, and Nexus servers. Jenkins is configured for continuous integration to regularly merge code, run builds and tests. SonarQube is added for quality analysis. Nexus is used as a repository manager to store dependencies and artifacts. The document provides steps to install and configure each tool and integrate them to set up the continuous integration pipeline.

Uploaded by

SolankiManish
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
277 views

C I-Jenkins

The document describes setting up a continuous integration workflow using Jenkins, SonarQube, and Nexus. It involves creating EC2 instances for Jenkins, SonarQube, and Nexus servers. Jenkins is configured for continuous integration to regularly merge code, run builds and tests. SonarQube is added for quality analysis. Nexus is used as a repository manager to store dependencies and artifacts. The document provides steps to install and configure each tool and integrate them to set up the continuous integration pipeline.

Uploaded by

SolankiManish
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 83

Logic Labs Technologies www.logiclabstech.

com

A Project Demonstration on Continuous Integration using Jenkins,


SonarQube and Nexus

What is Continuous Integration (C.I)?

Continuous integration is a DevOps software development practice where


developers regularly merge their code changes into a central repository, after
which automated builds and tests are run.
The key goals of continuous integration are to find and address bugs quicker,
improve software quality, and reduce the time it takes to validate and release
new software updates.

Benefits:
A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

2
Process of CI:-

Continuous Integration WorkFlow:-


A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

Pre-requisites:

1. Basic understanding of Jenkins


2. Basic knowledge of EC2 instances and linux
3. Awareness of Tools such as Nexus and SonarQube

Tools used:

Jenkins Git Maven SonarQube


Checkstyle AWS EC2 Nexus3
A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

4
Stage -1

Key pair setup


Login to the AWS management console → EC2 service→ Keypair and Create
a new keypair for the purpose of creating EC2 instances
A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

5
Security Groups setup
1. Login to AWS console-> Ec2-> Security Groups
2. Create three Security Groups (S.Gs) one for each- Jenkins, Sonar and
Nexus
3. Edit inbound rules for each security group as per the screenshot below
and leave outbound as it is.
4. If unclear about inbound rules, set “Allow all” for the practice purpose.

Creating security groups


A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

6
A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

7
A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

Server setup

We need to create 3 servers for Jenkins, Sonar and Nexus3.

Step1: clone source code and user data from repository

https://github.com/gnsharma530/Logiclabs-cidemo.git
A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

Step2: checkout to ci-jenkins branch and open userdata folder:


Commands to checkout branch:
git checkout ci-jenkins
cd userdata
Step3 : observe the files in it

step4 : open the AWS console to create the server ec2 instances

AWS console→ ec2→ create instance

Choice of Instance:
Jenkins:t2.small
SonarQube:t2.small
Nexus: t2.medium

-Select the relevant security groups


-paste the proper user data from the user data folder of the repository.

Clone the repository to the user data:


https://github.com/gnsharma530/Logiclabs-cidemo.git
A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

10

Step 4.1:
Jenkins server creation : OS→ UBUNTU

Instance type → t2 small/medium

** Avoid t2 micro as it might not handle the load smoothly


A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

11

Copy user data from the cloned repo and paste in the user data field. Select
the relevant security group

https://github.com/gnsharma530/Logiclabs-cidemo/tree/ci-jenkins/userdata
A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

12
A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

13

Step 5: Repeat the same steps for the below servers

Sonatype Nexus3 server:

OS: Centos7 & Instance type: t2 medium

NEXUS SERVER SETUP


A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

14
A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

15
A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

16
A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

17
A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

18
A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

19
SONARQUBE SERVER SETUP:

OS: Ubuntu Instance type: t2 medium


A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

20
A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

21
A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

22
A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

23

Verifying the installation:

1. Jenkins setup verification:


a. Login using public ip of jenkins server followed by port number
Eg: 55.52.32.1:8080
b. When the initial screen asks for Initial admin password, look into
the server via ssh and copy the initial admin password
2. Sonar Setup verification
a. Login using public ip of sonar server
b.
3. Nexus setup Verification:
a. Login using public ip of Nexus server followed by port number
Eg: 55.52.32.1:8081
A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

24
A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

25
Validating Nexus configuration:

SSH into nexus server to get admin password


A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

26

If your antivirus throws an error, please make necessary changes


accordingly…
A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

27

There will be option to change the default password.

Select the below given settings for anonymous access..


A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

28

Go to browser option and create new repositories:


1. Maven release
2. Maven central
A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

29
3. Maven group
Repositories→ create new repository→ Maven2 (hosted)

Fill in the details as given in the screenshot below.


A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

30
Start with the release repository, then proceed to the central repo and finally
create a group repository.
A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

31

The above step is to save dependencies from maven repo to nexus repo.
A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

32

Create a group repository


A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

33

Add the relevant repositories already created to the group repository as given
below.
A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

34

If needed, a snapshot repository can be created from maven2(host) type and


change the policy from release to snapshot...however for this demo, we aren’t
using a snapshot repo.

Inorder for maven to pick up dependencies from nexus repo instead of public
repo, we provide necessary details in settings.xml file in our users directory.

Note: the text editor used in this demonstration is sublime text and any other
alternative can be used.
A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

35

We will mention in jenkins to use this settings.xml file instead of the default
one in the .m2 folder of source code.

In the settings.xml and pom.xml files, we mention the variables where the
repository values and server URLs will be passed.

POST INSTALLATION CONFIGURATION

JENKINS:

1. Initial admin password can be obtained by logging in to the jenkins


ubuntu server and going to the path:
2. /var/lib/jenkins/secrets/initialadminpassword
3. Create a new admin password when prompted
4. Select install suggested plugins
5.
A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

36

Either use putty or use git bash to ssh into the instance
A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

37
A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

38

Wait till all the suggested plugins are installed


A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

39

Give your desired values for username and password, select continue to
configure further steps.
A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

40
Creating a JENKINS Job:

Give a proper name (eg: CI-Jenkins1) and select freestyle project and click on
ok to create a new jenkins job.

1. Provide settings for the job as given in the screenshots below.


A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

41
A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

42

We pass the goals as “install - DskipTests” to skip unit test as of now and only
package our source code

SET VARIABLES:
Create a properties file and fill in the below given details. Change the below
properties as per your server configurations

We obtain the necessary details from nexus repository configurations.


Paste the same values as you have given.
The values given in below screenshots may be different from what you might
have given.
A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

43

Copy these properties into the jenkins properties option;

Also provide ‘File path’ to settings.xml file as settings file in filesystem..


A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

44
For that, go to settings file → file path→ type “settings.xml”
Save the file.. And click on build now option to test our first build job.
A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

45

After the build is successful, proceed to the next steps as given below.

Verify whether the dependencies are getting created in the nexus repo :
A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

46

Create the second job:


Name it as “Test” or “Unit-Test”.

Select freestyle and copy everything from Build job. For this select the last
option in the screen and give the name of the job to be copied from.
A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

47

Similarly create another job for performing “integration Tests”.


A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

48

Change maven build goals as follows:

For Test job - test


For Integration -> verify -DskipUnitTests
A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

49

Inorder to perform static code analysis, we create a new step and name it
code-analysis (you can name it as you wish).
A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

50

Select copying settings from build pipeline and Click on ok

Install jenkins plugins :


→ Warnings next generation plugin
A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

51

Add a post build action to record compiler warnings and static analysis results
A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

52

In the tools option, select Checkstyle.

Run the job with other settings same. After success observe the checkstyle
results as shown below.
A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

53
A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

54
SONAR QUBE configuration:
Login to sonarQube with public IP.Usually Sonar Qube works on port 9000,
however as we are installing it along with Nginx, we need not provide any port
number after public ip in the browser to access sonar.
A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

55
Change the default password afterwards.

Go to Administrator → my account → security→ Generate tokens


A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

56

Create a token by the name sonartoken. Copy the token and use it in jenkins.

Get sonar plugin in Jenkins:


Jenkins → manage jenkins → manage plugins → Available

Note: If these plugins are deprecated by the time this document is used,
please look for alternatives…

Configure sonar in jenkins:


Global tool configuration→
A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

57

Goto jenkins→ configuration→ add sonar and enable environmental variables


A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

58

Select add credentials to add sonar token. If it doesn’t open, save without
adding a token and later reopen the configuration page and check again.

save the configuration after adding the sonar token at the sonar authentication
token.
A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

59
Quality gates give us the option to pass the build to next stages if only certain
criteria are fulfilled.
Sample Quality Gate configuration is given below.

Save quality gates configuration


A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

60

copy the sonar analysis properties from the file in the


source directory with name ‘sonar-analysis-properties’.
Add a new job in jenkins for sonar scanner code analysis.
A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

61

copy paste the variables from the file above mentioned.

If the build fails because of checkstyle issues, it can be removed


from maven targets step for this demonstration.
A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

62

Verification of Static code Analysis from sonar server:

After Jenkins job is complete, login to sonar server to verify and obtain the
static code analysis results.

(Optional)For experimentation purposes, the name of the branch in the jenkins


job can be changed to vp-rem and check the sonar results after running the
job.
A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

63

Creating Quality Gates:


The below screenshot shows how to configure Quality gates.
A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

64
A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

65
A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

66
A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

67
Copying Artifact Stage:

The build which passes through these stages and ready to be deployed is
called an Artifact in SDLC lifecycle.
The artifacts are stored and versioned using Artifacts repository.
For this demonstration purpose, Sonatype Nexus-3 is being used.

Before that let’s install a relevant plugin in the Jenkins .


1. Copy Artifact plugin
2. Zentimestamp plugin
A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

68

Create a new step in Jenkins for Deploying artifact to nexus.

click on add build step and select artifact upload option to give artifact details
A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

69

click on add build step and select nexus artifact uploader option to give artifact
details
Add the credentials of Nexus server in the Jenkins credentials provider.
A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

70
A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

71
A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

72

Note: Make sure you don’t repeat http while giving the nexus pvt URL.

Give the time format as given in the screenshot below.


A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

73
A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

74

VALIDATE Artifact Deployment to Nexus repository:


Goto Nexus server→ Browse repo → release repository

BUILDING Pipeline:
A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

75
In jenkins install the pipeline plugin as shown below. It helps in visually
appealing pipeline view in Jenkins.

Click on the + symbol besides All in the jobs dashboard to add a new view.
A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

76

Give the name of the first job to be started .


A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

77

Click on Run to start the pipeline. Observe that all the downstream Jobs are
performed sequentially.

Verify that all the jobs are properly configured for downstream jobs/upstream
jobs.
A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

78
Please make sure the pipeline flow is as shown below.
CI jenkins Build → UnitTest→ Integration Test→ CodeAnalysis → SonarScanner
Code Analysis → Deploy to Nexus
A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

79
A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

80

Click on the console button on each of the jobs to see the logs
A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

81

Automating the build pipeline triggering:

Enable poll scm or github webhooks and observe that the pipeline is triggered
automatically whenever any commit happens in the SCM tool (Github)
A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

82
Eg: 1 */5 * * * = check for commits and start building at every 5 hour interval
of every day.

Note: Inorder to verify, create your own repo which is cloned from the original
repo and experiment with this automated pipeline triggering mechanism.
A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus

83

Summary:

In this Demonstration, we have witnessed how a C.I. pipeline can be built


using tools such as jenkins, sonarQube and Nexus. We have observed how
the source code commit by developer triggers a pipeline which starts with
build job followed by Unit test, Integration test, Code analysis using
SonarQube scanner and finally a well tested artifact is uploaded into Nexus
repository.

You might also like