0% found this document useful (0 votes)
28 views15 pages

DevOps Professional

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)
28 views15 pages

DevOps Professional

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/ 15

Infosys Certified DevOps Professional

Hands-On based on Playground work Experience

JAVA DevOps

Setting up the configuration for the Pipeline Creation

Pre-requisites:

Installing Plugins to Jenkins:

 Go to Jenkins URL in a new tab and login with the given credentials which will be available in the
table.
 Open “Manage Jenkins” -> Scroll down and search for “Manage Plugins” -> Click on Advanced
tab.
 Scroll down to Upload plugin option.
 Click on Browse button to install the Jenkin plugins,
 Click on Jenkins-Plugins folder. It consists of 3 sub folders.
 Build-pipeline plugin
 Deploy.hpi
 Git.hpi
 Upload the above mentioned 3 sub folders separately until everything will be success.
 Open “Manage Jenkins” -> Scroll down and search for “Manage Plugins” -> Click on Available
tab.
 You may need to download other plugins. Select the below plugins from Available tab and
“Install without Restart” option.
 Note: Copy the plugin name one by one and paste it in the Filter search box and check the box
to select the plugin and click ->“Install without Restart” option.

 Copy Artifact
 Workspace cleanup
 Cobertura
 Folders
 Artifactory
 Junit
 Tool Configurations to be done in Manage Plugin -> Global Tool Configuration.
 Git: Set as /usr/bin/git in the git path(Leave Git name as Default)
 JDK: Set the name to JDK and path to JDK as /usr/lib/jvm/java-8-openjdk-amd64
 Maven: Create a New Maven Installation name it as MyMaven with the path pointing to
/opt/maven. Use this in the configuration of the pipeline while invoking Maven
targets(Uncheck Install Maven automatically).
Setting up Artifactory folder:

Step 1:

 Go to Artifactory URL in a new tab and login with the given credentials which will be available in
the table.
 From the admin option, under Repositories choose Local -> Create new repository using (+) New
option.
 Create a local repository key on the JFrog server from Firefox with the folder name as
mentioned in the pom.xml of the project in eclipse, within the tag.
 Create a New Local repository by clicking +New button present at the right corner.
 Enter the Package type & Repository Key values as given below,
 Package Type: Maven
 Repository Key: Calc_Dev_Snapshot
 Click Save and Finish.

Step 2:

 To allow automated deployment to this repository through Jenkins pipeline, set the security
permission as mentioned next,
 Click on Admin tab on the left and go to Permissions under Security option.
 Select the Anything option.
 Select the tab for Groups and click readers button and select on the Manage checkboxes
[Delete/Overwrite, Deploy/Cache, Annotated, Read] as mentioned in the screenshots.
 Select the tab for Users and click anonymous button and select on the Manage checkboxes
[Delete/Overwrite, Deploy/Cache, Annotated, Read] as mentioned in the screenshots.
 Check all the Checkboxes in Repository Actions and Build Actions for Groups and Users tab.
 Click on Save and Finish.

Creating Quality Profiles using SonarQube:

 Go to SonarQube URL in a new tab and login with the given credentials which will be available in
the table.
 Note: If you are unable to see Log In button on top-right corner of the SonarQube Dashboard,
Zoom put browser window using CTRL (-).
 Go to the Quality Profiles option.
 Click on the Sonar Way present under the Java, 1 profile(s).
 Click on Actions button present at the top right corner of the screen
 Select Actions -> Copy and enter the New Quality profile name in the input box(New Name)
“___”(given in the question paper), and click copy button.
 Make the newly created profile as Default one (By clicking Actions->Set as Default).
 Finish.
Exercise 1:

Operations on Git Repository Using Eclipse IDE

 Open Eclipse IDE.


 Close the Welcome Page.
 Expand the project(com.ms.calc[Project master]) present in the ´Project Explorer´ tab and open
the “index.jsp” file inside src/main/webapp.
 Change the background(<body bgcolor=”white”>) color to “Blue” in Line 8 and save the file.
 Right click on project in “Project Explorer”->Team->Commit->Enter the appropriate commit
message in the input box and click on the Commit Button.
 The new change has now been committed.

Exercise 2 (55 Marks)

Jobs Creation and Configuring build pipeline in Jenkins.

Go to Jenkins URL and follow the steps as given below.

Create a folder for Calculator Project build jobs. Within this, create the following Jobs as given below,

 Setup
 Compile
 Static Analysis
 UnitTest
 Code Coverage
 War
 ToArtifactory
 SmokeTest

Create a Folder name Central_CI_Pipeline.

Steps to create a Pipeline FOLDER:

 Click on ´New Item´ in the Jenkins Home page.


 Enter an item name (Central_CI_Pipeline) in the text box.
 Click on the Folder box shown below.
 Then, Click on Ok option.
 It will get redirected to next page, ask you to enter Display name & Description values
(Central_CI_Pipeline)
 After entering the values click on Apply & Save button.
 Folder (Central_CI_Pipeline) will be created successfully.

Steps to create a Jobs:

 Under this folder Folder (Central_CI_Pipeline), we have to create the Jobs as given below,
1) Setup
2) Compile
3) Static Analysis
4) UnitTest
5) Code Coverage
6) War
7) ToArtifactory
8) SmokeTest
 Click on ´New Item´ in the Jenkins Home page.
 Enter an item name (Setup) the text box.
 Note: For All Jobs creation, we have to Choose Freestyle projects
 Select the option as FreeStyleProject as shown below.
 Then, Click on Ok option.
 New Job will be created for SETUP.

Steps to Configure the SETUP job:

Actions Inputs to give


Description Setup
Check to the Discard Old Builds:
Days to keep builds: 3
Max # of builds to keep: 2
Source code Management:
Select "Git"
Repository URL /root/Desktop/user_repo/Project/.git
Build Triggers:
Poll SCM H/2 * * * *
Build Environment:

Delete Workspace before build starts Select that checkbox


Build:
1) Choose "Invoke top-level Maven targets"
Select Maven Version as MyMaven
Goals clean(lower case)
Post Build Actions
1)Choose "Archieve the Artifacts"
Files to Archieve **/*
2) Choose "Build other projects"
Projects to Build Compile(Next Job to Build)
 Click on Apply and Save.
 Wait for the Job to be run and Success(Blue Ball with #1) will be display.
 Click on “Up”(with an arrow pointing up).
 Setup Job will get merged inside the folder(Central_CI_Pipeline).
2) Compile

 Click on ´New Item´ in the Jenkins Home page.


 Enter an item name (compile) the text box.
 Note: For All Jobs creation, we have to Choose Freestyle projects
 Select the option as FreeStyleProject as shown below.
 Then, Click on Ok option.
 New Job will be created for COMPILE.
Compile

Actions Inputs to give


Description Compile
Check to the Discard Old Builds:
Days to keep builds: 3
Max # of builds to keep: 2
Build Environment:
Delete Workspace before build starts Select that checkbox
Build:
1) Copy Artifacts from Another projects
Project Name Setup
Stable build only Select that checkbox
Artifacts to copy **/*
2) Choose "Invoke top-level Maven targets"
Select Maven Version as MyMaven
Goals compile(lower case)
Post Build Actions
1)Choose "Archieve the Artifacts"
Files to Archieve **/*
2) Choose "Build other projects"
Projects to Build StaticAnalysis(Next Job to Build)
 Click on Apply and Save.
 Wait for the Job to be run and Success(Blue Ball with #1) will be display.
 Click on “Up”(with an arrow pointing up).
 Compile Job will get merged inside the folder(Central_CI_Pipeline).
3) Static Analysis

 Click on ´New Item´ in the Jenkins Home page.


 Enter an item name (Static Analysis) the text box.
 Note: For All Jobs creation, we have to Choose Freestyle projects
 Select the option as FreeStyleProject as shown below.
 Then, Click on Ok option.
 New Job will be created for Static Analysis.

Static Analysis

Actions Inputs to give


Description StaticAnalysis
Check to the Discard Old Builds:
Days to keep builds: 3
Max # of builds to keep: 2
Build Environment:
Delete Workspace before build starts Select that checkbox
Build:
1) Copy Artifacts from Another projects
Project Name Compile
Stable build only Select that checkbox
Artifacts to copy **/*
2) Choose "Invoke top-level Maven targets"
Select Maven Version as MyMaven
Goals sonar:sonar(lower case)
Post Build Actions
1)Choose "Archieve the Artifacts"
Files to Archieve **/*
2) Choose "Build other projects"
Projects to Build UnitTesting(Next Job to Build)
 Click on Apply and Save.
 Wait for the Job to be run and Success(Blue Ball with #1) will be display.
 Click on “Up”(with an arrow pointing up).
 Static Analysis Job will get merged inside the folder(Central_CI_Pipeline).

4) Unit Testing

 Click on ´New Item´ in the Jenkins Home page.


 Enter an item name (Unit testing) the text box.
 Note: For All Jobs creation, we have to Choose Freestyle projects
 Select the option as FreeStyleProject as shown below.
 Then, Click on Ok option.
 New Job will be created for Unit Testing.

Unit Testing

Actions Inputs to give


Description UnitTesting
Check to the Discard Old Builds:
Days to keep builds: 3
Max # of builds to keep: 2
Build Environment:
Delete Workspace before build starts Select that checkbox
Build:
1) Copy Artifacts from Another projects
Project Name StaticAnalysis
Stable build only Select that checkbox
Artifacts to copy **/*
2) Choose "Invoke top-level Maven targets"
Select Maven Version as MyMaven
Goals test(lower case)
Post Build Actions
1)Choose "Archieve the Artifacts"
Files to Archieve **/*
2) Choose "Build other projects"
Projects to Build CodeCoverage(Next Job to Build)
3) Publish Junit Test result Report
Test Reports XMLs target/surefire-reports/*.xml
 Click on Apply and Save.
 Wait for the Job to be run and Success(Blue Ball with #1) will be display.
 Click on “Up”(with an arrow pointing up).
 Unit testing Job will get merged inside the folder(Central_CI_Pipeline).

5) Code Coverage

 Click on ´New Item´ in the Jenkins Home page.


 Enter an item name (Code Coverage) the text box.
 Note: For All Jobs creation, we have to Choose Freestyle projects
 Select the option as FreeStyleProject as shown below.
 Then, Click on Ok option.
 New Job will be created for Code Coverage.
Code Coverage

Actions Inputs to give


Description CodeCoverage
Check to the Discard Old Builds:
Days to keep builds: 3
Max # of builds to keep: 2
Build Environment:
Delete Workspace before build starts Select that checkbox
Build:
1) Copy Artifacts from Another projects
Project Name UnitTesting
Stable build only Select that checkbox
Artifacts to copy **/*
2) Choose "Invoke top-level Maven targets"
Select Maven Version as MyMaven
Goals cobertura:cobertura(lower case)
Post Build Actions
1)Choose "Archieve the Artifacts"
Files to Archieve **/*
2) Choose "Build other projects"
Projects to Build War(Next Job to Build)
 Click on Apply and Save.
 Wait for the Job to be run and Success(Blue Ball with #1) will be display.
 Click on “Up”(with an arrow pointing up).
 Code Coverage Job will get merged inside the folder(Central_CI_Pipeline).

6) War

 Click on ´New Item´ in the Jenkins Home page.


 Enter an item name (War) the text box.
 Note: For All Jobs creation, we have to Choose Freestyle projects
 Select the option as FreeStyleProject as shown below.
 Then, Click on Ok option.
 New Job will be created for War.
War

Actions Inputs to give


Description War
Check to the Discard Old Builds:
Days to keep builds: 3
Max # of builds to keep: 2
Build Environment:
Delete Workspace before build starts Select that checkbox
Build:
1) Copy Artifacts from Another projects
Project Name Compile
Stable build only Select that checkbox
Artifacts to copy **/*
2) Choose "Invoke top-level Maven targets"
Select Maven Version as MyMaven
Goals war:war(lower case)
Post Build Actions
1)Choose "Archieve the Artifacts"
Files to Archieve **/*
2) Choose "Build other projects"
Projects to Build ToArtifactory(Next Job to Build)
 Click on Apply and Save.
 Wait for the Job to be run and Success(Blue Ball with #1) will be display.
 Click on “Up”(with an arrow pointing up).
 War Job will get merged inside the folder(Central_CI_Pipeline).
7)ToArtifactory

 Click on ´New Item´ in the Jenkins Home page.


 Enter an item name (ToArtifactory) the text box.
 Note: For All Jobs creation, we have to Choose Freestyle projects
 Select the option as FreeStyleProject as shown below.
 Then, Click on Ok option.
 New Job will be created for ToArtifactory.

ToArtifactory

Actions Inputs to give


Description ToArtifactory
Check to the Discard Old Builds:
Days to keep builds: 3
Max # of builds to keep: 2
Build Environment:
Delete Workspace before build starts Select that checkbox
Build:
1) Copy Artifacts from Another projects
Project Name War
Stable build only Select that checkbox
Artifacts to copy **/*
2) Choose "Invoke top-level Maven targets"
Select Maven Version as MyMaven
Goals deploy(lower case)
Post Build Actions
1)Choose "Archieve the Artifacts"
Files to Archieve **/*
2) Choose "Build other projects"
Projects to Build SmokeTest(Next Job to Build)
 Click on Apply and Save.
 Wait for the Job to be run and Success(Blue Ball with #1) will be display.
 Click on “Up”(with an arrow pointing up).
 ToArtifactory Job will get merged inside the folder(Central_CI_Pipeline).
8) SmokeTest

 Click on ´New Item´ in the Jenkins Home page.


 Enter an item name (SmokeTest) the text box.
 Note: For All Jobs creation, we have to Choose Freestyle projects
 Select the option as FreeStyleProject as shown below.
 Then, Click on Ok option.
 New Job will be created for SmokeTest.

SmokeTest

Actions Inputs to give


Description SmokeTest
Check to the Discard Old Builds:
Days to keep builds: 3
Max # of builds to keep: 2
Build Environment:
Delete Workspace before build starts Select that checkbox
Build:
1) Copy Artifacts from Another projects
Project Name ToArtifactory
Stable build only Select that checkbox
Artifacts to copy **/*
Post Build Actions
1)Choose "Archieve the Artifacts"
Files to Archieve **/*
2)Deploy war/ear to a container
WAR/EAR file */*.war
Contect Path /com.ms.calc
Container -> Click Add Container Choose Tomcat 8.x server
Credentials: Click Add -> Jenkins or Central_CI_pipeline
Username Admin
Password s3cret
Add the entered credentials by clicking the small triangle (drop down) button (next to -
none-)
Tomcat URL http://localhost:8080
 Click on Apply and Save.
 Wait for the Job to be run and Success(Blue Ball with #1) will be display.
 Click on “Up”(with an arrow pointing up).
 Smoke Test will get merged inside the folder(Central_CI_Pipeline).

Exercise 1 got over

Note: Please click on Execute button to execute all the Jobs one by One. (Important)

To view the Test Cases Passed/ Failed, please click the “View Result” Button

Exercise:2 (6 Marks)

Exercise on Unit Testing

Things to change in pom.xml(Eclipse)

 Open Eclipse IDE.


 Expand the project(com.ms.calc[Project master]) present in the ´Project Explorer´ tab and open
the “pom.xml”(present at the last, next to effective pom.xml).
 Replace the values of <sonar.projectKey>CI_2</sonar.projectKey> -> Line no.31
 Replace the values of <name>CI_Calculator_UT</name> -> Line no.69
 Press Ctrl+S to save the changes.
 Then Right click on project in “Project Explorer”->Team->Commit->Enter the appropriate
commit message in the input box and click on the Commit Button.
 The new change has now been committed.

Branch Creation for the Java project: ci_calculator_ut

 Right click on project in “Project Explorer”->Team->Switch To->New Branch->Enter the branch


name in the input box and click on the Finish Button.
 New branch will be created for Unit Testing.

Steps to Fail the Test Class(CalculatorTest.java)

 We need to Fail any one of the test methods in CalculatorTest.java file


 Expand the project(com.ms.calc[Project master]) present in the ´Project Explorer´ tab and open
the “CalculatorTest.java” file present inside src/test/java/ut/CalculatorTest.java
 Do change any number values in any one of the methods(testAdd, testSub, testMul, testDiv) to
Fail the test methods.
 Press Ctrl+S to save the changes.
 Then Right click on project in “Project Explorer”->Team->Commit->Enter the appropriate
commit message in the input box and click on the Commit Button.
 The new change has now been committed.

Jobs Creation and Configuring build pipeline in Jenkins.

We need to create one separate Folder for Unit Testing. Central_CI_Pipeline_UT

Create a Folder name Central_CI_Pipeline_UT.

Steps to create a Pipeline FOLDER:


Hint: We can re-use or copy the previous Exercise’s folder (Central_CI_Pipeline)

 Click on ´New Item´ in the Jenkins Home page.


 Enter an item name (Central_CI_Pipeline_UT) in the text box.
 Click on the Folder box shown below.
 Scroll down to the page, there we can able to see the option ->Copy from.
 Enter the folder name from which we are going to copy(Central_CI_Pipeline).
 Then, Click on Ok option.
 After entering the values click on Apply & Save button.
 Folder (Central_CI_Pipeline_UT) will be created successfully.
 All the 8 jobs under Central_CI_Pipeline folder will be successfully copier here.
 We can delete the unwanted jobs(5,6,7,8) by right clicking the job & click Delete Project.
 For the jobs(1,2,3,4), we need to configure(right clicking the job & click Configure) the jobs by
clicking Apply and Save option.

 In Exercise 2 the above mentioned job “Unit Testing” should Fail, means it should display the
RED ball with thunder symbol.

Exercise 2 got over

Note: Please click on Execute button to execute all the Jobs one by One. (Important)

To view the Test Cases Passed/ Failed, please click the “View Result” Button.

Exercise:3 (9 Marks)

Exercise on Static Analysis SonarQube

Things to change in pom.xml(Eclipse)

 Open Eclipse IDE.


 Expand the project(com.ms.calc[Project master]) present in the ´Project Explorer´ tab and open
the “pom.xml”(present at the last, next to effective pom.xml).
 Replace the values of <sonar.projectKey>CI_3</sonar.projectKey> -> Line no.31
 Replace the values of
<distributionManagement><name>CI_Calculator_Sonar</name></distributionManagement> ->
Line no.69
 Press Ctrl+S to save the changes.
 Then Right click on project in “Project Explorer”->Team->Commit->Enter the appropriate
commit message in the input box and click on the Commit Button.
 The new change has now been committed.

Branch Creation for the Java project: ci_calculator_sonar


 Right click on project in “Project Explorer”->Team->Switch To->New Branch->Enter the branch
name in the input box and click on the Finish Button.
 New branch will be created for Unit Testing.

Steps to create Quality Gate in Sonar Gate:

 Go to SonarQube URL in a new tab and login with the given credentials which will be available in
the table.
 Note: If you are unable to see Log In button on top-right corner of the SonarQube Dashboard,
Zoom put browser window using CTRL (-).
 Go to the Quality Gates option.
 Click on create button to create a new quality gate and give it a name.
CI_Calculator_Quality_Gate.
 After that we need to set conditions for Minor Issues.
 We need to set the limitation, if Warning is more than 5 and Error is more than 3.

Jobs Creation and Configuring build pipeline in Jenkins.

We need to create one separate Folder for Unit Testing. Central_CI_Pipeline_Sonar

Create a Folder name Central_CI_Pipeline_Sonar.

Steps to create a Pipeline FOLDER:

Hint: We can re-use or copy the previous Exercise’s folder (Central_CI_Pipeline_UT)

 Click on ´New Item´ in the Jenkins Home page.


 Enter an item name (Central_CI_Pipeline_Sonar) in the text box.
 Click on the Folder box shown below.
 Scroll down to the page, there we can able to see the option ->Copy from.
 Enter the folder name from which we are going to copy (Central_CI_Pipeline_UT).
 Then, Click on Ok option.
 After entering the values click on Apply & Save button.
 Folder (Central_CI_Pipeline_Sonar) will be created successfully.
 All the 4 jobs under Central_CI_Pipeline_UT folder will be successfully copier here.
 We can delete the unwanted job(4) by right clicking the job & click Delete Project.
 For the jobs (1,2,3), we need to configure(right clicking the job & click Configure) the jobs by
clicking Apply and Save option.

 In Exercise3 the above mentioned job “Static Analysis” should Fail, means it should display the
RED ball with thunder symbol.

Exercise 3 got over

Note: Please click on Execute button to execute all the Jobs one by One. (Important)

To view the Test Cases Passed/ Failed, please click the “View Result” Button.

You might also like