C I-Jenkins
C I-Jenkins
com
Benefits:
A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus
2
Process of CI:-
Pre-requisites:
Tools used:
4
Stage -1
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.
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
https://github.com/gnsharma530/Logiclabs-cidemo.git
A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus
step4 : open the AWS console to create the server ec2 instances
Choice of Instance:
Jenkins:t2.small
SonarQube:t2.small
Nexus: t2.medium
10
Step 4.1:
Jenkins server creation : OS→ UBUNTU
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
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:
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
24
A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus
25
Validating Nexus configuration:
26
27
28
29
3. Maven group
Repositories→ create new repository→ Maven2 (hosted)
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
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
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.
JENKINS:
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
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.
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
43
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
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
48
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
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
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.
56
Create a token by the name sonartoken. Copy the token and use it in jenkins.
Note: If these plugins are deprecated by the time this document is used,
please look for alternatives…
57
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.
60
61
62
After Jenkins job is complete, login to sonar server to verify and obtain the
static code analysis results.
63
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.
68
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.
73
A Project Demonstration on Continuous Integration using Jenkins, SonarQube and Nexus
74
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
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
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: