devops
devops
4.
Create CI Pipeline using Jenkins
AIM
To build a maven build pipeline in Azure.
PROCEDURE
STEP1: Create an account on the Azure DevOps website.
Goto https://azure.microsoft.com/en-in/products/devops/website and sign in using a GitHub
account.
Create a new organization with a suitable name of your choice. Here dhineshkumar1729 is the
organization name.
Create a new project named DevOps in private mode.
Create a project by clicking on the New Project option, choose an appropriate name and select
the following features as mentioned in the image (Build system: Maven and Language: Java)
1.A sample code has been generated. Now press ALT+F12 to open a terminal inside the IDE.
RESULT
Thus, a maven build pipeline has been created using Azure
EX NO: 2 Run Regression Tests Using Maven Build Pipeline
DATE: in Azure
AIM
To run regression tests using the Maven build pipeline in Azure.
PROCEDURE
Wait for some time until the indexes of the project have been updated.
Add the following snippet of code into pom.xml
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
</dependencies>
Once the changes have been made click on the referred button to update the changes made to
pom.xml or for simplicity just press CTRL + SHIFT + O
Now, inside the java folder on the Test directory create a package named org.example (Right
click on java folder inside the Test directory choose Newand select package)
Right-click on the package and create a new class named Main Test
$gitinit
$gitadd.
$gitcommit-m“regression”
$gitbranch-Mmain
$gitremoteaddoriginYOUR_REPOSITORY_LINK
$gitpush-uoriginmain
If prompted for permission then select Approve and Install on GitHub website.
#Maven
#BuildyourJavaprojectandruntestswithApacheMaven.
#Add steps that analyze code, save build artifacts, deploy ,and more:
#https://docs.microsoft.com/azure/devops/pipelines/languages/java
trigger:
-main
pool:
vmImage:'ubuntu-latest'
steps:
task: Maven@3 inputs:
mavenPomFile: 'pom.xml' mavenOptions: '-Xmx3072m'javaHomeOption:
'JDKVersion'jdkVersionOption: '11' jdkArchitectureOption: 'x64' goals: 'clean test'
task:PublishTestResults@2 inputs:
test ResultsFiles:'**/surefire-reports/TEST-*.xml'testRunTitle: 'JUnit Test Results'
Click on the Save and Run button to commit the changes and execute the pipeline.
The following results can be obtained on the output page.
From the test results tab it can be found that the tests passed.
RESULT
Thus, regression tests have been run using the Maven Build Pipeline in Azure.
EX NO: 3 Install Jenkins in Cloud
DATE:
AIM
To install Jenkins in the cloud(AWS).
PROCEDURE
STEP1:Create an AWS account
Go to https://aws.amazon.com/ and create an AWS Account.
Confirm your identity by providing the PAN card number associated with the name of the user.
Verify the phone number and perform a security check.
Sign in as a Root user by providing the appropriate email address and password.
STEP2: Create an EC2 instance.
Search EC2 in the search bar and choose EC2 from the services tab.
Select the Jenkins Demo instance and click on the Connect button.
Click on the Security tab and choose the Security Groups option.
Click on the Connect but to at the bottom after choosing Connect using EC2 Instance Connect.
A terminal is opened on a new tab in the same browser.
$sudowget-O/usr/share/keyrings/jenkins-keyring.asc\
https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key
$echodeb[signed-by=/usr/share/keyrings/jenkins-keyring.asc]\ https://pkg.jenkins.io/debian-
stable binary/ | sudo tee \
/etc/apt/sources.list.d/jenkins.list>/dev/null
$sudoapt-getupdate
$sudoapt-getinstallfontconfigopenjdk-17-jre
$sudoapt-getinstallJenkins
$sudosystemctlstartJenkins
$sudosystemctlenableJenkins
$sudosystemctl status Jenkins
Copy the public IP address found below the terminal and copy the address. Open a new tab, paste
the IP address and add :8080 at the last.
Example:51.20.64.160:8080
STEP4: Configuring Jenkins
Jenkins will be initially locked. The password will be located at the location provided on the
screen. Copy it.
Go back to the terminal and execute
$sudocat/var/lib/Jenkins/secrets/initial Admin Password
Copy the password from the terminal, paste it on the Jenkins webpage and press Continue.
Select Installed suggested plugins to install the most used plugins in Jenkins.
The installation will take some time to complete.
Create a user login on the next page. Provide the necessary information and press
Save and Continue.
Check whether the Jenkins URL is the same as the one mentioned in the address bar and press
Save and Finish.
Now Jenkins has been successfully configured on the cloud. Click on Start using Jenkins to work
with it.
TheJenkinswebpagewouldlooklikebelow.Jobscanbebuilthere.
RESULT:
Thus, Jenkins has been install done the cloud.
AIM:
To create a CI pipeline using Jenkins.
PROCEDURE:
STEP1:Click and open this GitHub repository(https://github.com/benc-uk/python-demoapp.git). And
also click fork to make the changes in your own account.
(Note: The username and password in GitHub, Jenkins and Docker Hub website should be the same.)
STEP2: Now you have moved into your own GitHub account.
STEP4: Now, you can make the below changes in the code.
STEP6:Replace the above link with your own GitHub repository link.
STEP10: Now Enter the item name and select pipeline, then click on OK.
STEP13: In the Build history section, click on the builds then you will able to seethe console output
as ‘FINISHED: SUCCESS’. Now The Pipeline is built.
Torestartjenkins:
$sudosystemctlrestart Jenkins
STEP18:Open Browser and search for docker hub ,then create an account in docker hub.
STEP21:Scroll down for Pipeline. In the Script area, run the below code. pipeline {
agentany stages{
stage('GitCheckout'){ steps {
gitchangelog:false,poll:false,url:’’ }
}
stage('DockerBuild'){ steps {
sh"makeimage"
}
}
stage('DockerPush'){ steps {
script{
withDockerRegistry(credentialsId:’‘,toolName:’‘){ sh "make push"
}
}
}
}
}
}
STEP24: Again Click on pipe line and select the Snippet generator.
The Credentials will have been added in the Registry Credentials section select the docker below,
then click on Generate pipeline script.
RESULT:
Thus, the CI Pipeline has been successfully created.
AIM:
To create a CD pipeline in Jenkins and deploy it in the Cloud.
PROCEDURE:
STEP1: Click Repositories> python demo app>General .There, you will be able to see a command
under Docker commands. Copy that command.
STEP2 :Now, go to your Git Hub account .Scroll down to Containers and copy the command again
for future use.
stage('Docker Deploy'){
steps { script{
with Docker Registry (credentials Id: 'dbc54abf-de2b-42b8-a0d2-f5539c9b8997', tool Name:
'docker') {
sh" docker images"
sh" docker run-d--rm-it-p80:5000jayashriashokkumar28112003/python-
webapp: latest"
}
}
}
}
STEP5: To access the Python web app copy and paste the public IP of the AWS instance and include
port 5000 at the end of it. (For example: 41.204.111.57:5000)
RESULT:
Thus, the CD pipeline has been successfully created in Jenkins and deployed in the
Cloud.
AIM
To Create an Ansible Playbook for a simple web application infra structure.
PROCEDURE
STEP1: Create a directory named ansible-practice1 and then navigate in to that directory with the cd
command.
STEP2: Now create a playbook that contains the following content to be executed. The content to be
added in the playbook (playbook01.yml),
---
-hosts: local host tasks:
-name: Print message debug:
msg: Hello Ansible World
$ansible-playbook-iinventoryplaybook-01.yml-usammy
RESULT:
Thus, creating and executing an ansible playbook for a simple web application infrastructure has
been executed successfully.
PROCEDURE
Step 1: Create directory: `java application`. Step 2: Change to directory: `java application`. Step 3:
Run `gradle init` command.
Step4:Select project type(application).
Step5:Choose implementation language(Java).
Step6:Select build script language(Groovy).
Step7:Choose testing framework(JUnit4).
Step8:Enter project name.
Step9:Enter source package.
Select the project type (application, library, etc.) by typing `2` and pressing Enter for an application.
Enter the project name when prompted (default is the directory name) & Enter the source package
when prompted (default is the directory name).
AIM
To install Ansible, configure Ansible roles and write playbooks.
PROCEDURE
Step1: Refresh your system’s package index so that it is aware of the packages available. Run
the following command,
Step2:The Ansible package and its dependencies are available in the default package
repositories to install the latest Ansible version, add its ppa repository.
Step4:To check the list of directories and files present in the ansible ,run the command as,
$ls–la
Then check the host file by,
$sudo nano hosts
To view the role directory structure ,run the tree command followed by the role name.
Step6: Create three ansible roles as follows:
The prerequisites role–Install git.
The post gre sql role – Installs postgre sql service. The apache role–Installs the Apache
webserver. Use the following commands to create the above,
Step7: Define each role that you have created. To achieve this, you need to edit the main. yml
file located in the ‘tasks’ folder for each role.
First for prerequisites,
$cdprerequisites/tasks/
Then edit the main. Yml file by the command,
$sudo nano main.yml
Then add the content to this main. Yml file as # tasks file for prerequisites
-name: Install git apt:
name: git state: present
update_cache: yes
Next for PostgreSQL,
$cdPostgreSQL/tasks/
$sudo nano main .yml
Then add the content to this main. Yml file as, # tasks file for PostgreSQL
-name: Install PostgreSQL apt:
name: post gresql state: present update_cache: yes
-name: Start Post gre SQL service systemd:
Name :postgre sql state: started enabled: yes
Finally for the apache web server,
$cdapache/tasks/
Lastly, we are going to create a play book file called stack. Yml and call the roles by the
command,
$sudo nano stack .yml
Then add the content to this main. Yml file as
hosts: localhost become: true roles:
prerequisites
PostgreSQL
apache
Step8: Ensure that our roles are working as expected, and run the ansible playbook. Run the
following command,
$sudoansible-playbook stack.yml
Then check the versions to ensure that the packages were installed successfully,
$git--version
$ apachectl –v
RESULT
Thus, installing ansible ,configuring ansible roles and writing playbooks have been executed
successfully.