Deops Lab-1
Deops Lab-1
Name : ………………………………………………………
Reg.No : ………………………………………………………
Branch : ………………………………………………………
Year/Sem : ………………………………………………………
KARPAGAM INSTITUTE OF TECHNOLOGY
COIMBATORE - 641 105
DEPARTMENT
OF
ARTIFICIAL INTELLIGENCE AND DATA SCIENCE
institution as prescribed by Anna University Chennai for the III/VI during the year 2023-2024.
REGISTER NO : ………………………..
conducted on ……………………
COURSE OBJECTIVES:
LIST OF EXPERIMENTS:
ADDITIONAL EXPERIMENT
9. Modify Azure – Pipelines .Yaml File
COURSE OUTCOMES:
CO1: Understand different actions performed through Version control tools like Git.
CO2: Perform Continuous Integration and Continuous Testing and Continuous Deployment using
Jenkins by building and automating test cases using Maven & Gradle.
CO3: Ability to Perform Automated Continuous Deployment
CO4: Ability to do configuration management using Ansible
CO5: Understand to leverage Cloud-based DevOps tools using Azure DevOps
PO’s PSO’s
1 2 3 4 5 6 7 8 9 10 11 12 1 2 3
1 3 3 3 2 3 - - - - - - - 2 2 2
2 3 3 3 2 3 - - - - - - - 2 2 2
3 3 3 3 2 3 - - - - - - - 2 2 2
4 3 3 3 2 3 - - - - - - - 2 2 2
5 3 3 3 2 3 - - - - - - - 2 2 2
AVG 3 3 3 2 3 - - - - - - - 2 2 2
INDEX
MARKS
5. Create a CD pipeline in 20
Jenkins and deploy in Cloud
AIM:
To implement a Maven build pipeline to automate the build process of a Java application.
PROCEDURE:
Step 1: Open your web browser and navigate to Azure DevOps. Sign in with Azure DevOps
account.
Step 2: Create a New Project: Once logged in, click on "Projects" in the top left corner. Click
on the "New Project" button. Fill in the necessary details for your project (name,
description, visibility), and click "Create."
Step3: Setup Source Control: In your new project, navigate to the "Repos" Section. Import
or setup your Maven project in the source control system (e.g., Git).
Step 4: Create a New Build Pipeline: Navigate to the "Pipelines" section in your project. Click on
1
the "New pipeline" button. Choose your source repository (e.g.,GitHub,Azure Repos
Git).
Step 5: Select a Template: Azure DevOps will prompt you to choose a template. Search
for and select the "Maven" template.
Step 6: Configure the Pipeline: You'll be presented with a YAML editor for your pipeline.
Review and modify the YAML as needed. Make sure the pom.xml path is correctly specified.
The default is often $(System.Default Working Directory)/pom.xml. Customize Maven goals
and options if required.
Step 7: Build and Test: The default Maven task runs the clean install command. Adjust this
command if needed. Configure any additional Maven goals or options based on your project
requirements.
2
Step 8: Publish Artifacts (Optional): If your Maven build produces artifacts, Add a "Publish
Build Artifacts" task. Specify the path to the artifacts and choose where to publish them.
Step 9: Save and Queue: Save your pipeline configuration by clicking "Save" or "Save &
Queue." Optionally, queue a build to see it in action immediately.
3
Step10: Review Logs: Once the build is complete, review the logs to ensure that everything ran
successfully. Address any issues that may arise during the build process.
Step 11: Trigger Builds automatically (Optional): Configure triggers to automatically queue a build
whenever changes are pushed to the repository. Navigate to the "Triggers" tab in your
pipeline configuration to setup continuous integration.
Step 12: Setup Continuous Integration (Optional): Integrate your build pipeline with other
stages for continuous integration and delivery. Define deployment stages and tasks as
needed.
Step 13: Save and Run: Save your changes and run the pipeline to ensure that it functions as
expected. Monitor the pipeline for any errors or issues.
4
RESULT:
Thus, the setup of Maven Pipeline in Azure was built and implemented successfully.
5
Ex. No: 2
RUN REGRESSION TESTS USING MAVEN BUILD PIPELINE
Date:
AIM:
To implement a Maven build pipeline to automate the build process and run regression tests for a Java
application, ensuring that changes do not introduce new defects.
ALGORITHM:
Step 1: Initialize Maven: Set up the Maven environment for the project.
Step 2: Compile Code: Use Maven to compile the Java source code.
Step 3: Run Unit Tests: Execute unit tests using Maven Surefire Plugin.
Step 4: Run Regression Tests: Integrate regression tests into the build pipeline.
Step 5: Package Artifact: Package the application into a JAR or WAR file.
SOURCE CODE:
File 1: POM.xml
6
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.22.2</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
7
</dependencies>
</build>
</project>
File 2: HelloWorld.java
File 3: HelloTest.java
import org.junit.Test;
@Test
assertEquals(expected, actual);
8
RUN THE TEST:
mvn test
OUTPUT:
RESULT:
Thus, the code to build Maven pipeline was written and run the regression tests successfully.
9
Ex. No: 3
INSTALL JENKINS IN CLOUD
Date:
AIM:
To install and configure Jenkins on a cloud server to automate the build and deployment processes.
ALGORITHM:
Step 1: Choose any Cloud Provider such as AWS, GCP, Azure, etc.,
Step 2:Create an account in any one of the providers, consider AWS here for installing Jenkins.
Step 3: Create a key pair using Amazon EC2.
Step 4: Sign in to the AWS Management Console.
Step 5: Open the Amazon EC2 console by selecting EC2 under Compute.
Step 6: In the left-hand navigation bar, select Security Groups, and then select Create Security
group.
Step 7: In security group, select SSH, HTTP and create a group with specified IP address.
Step 8:To launch Amazon EC2 instance, follow the below steps:
Step 8.1: From the Amazon EC2 dashboard, select Launch Instance.
10
Step 8.2: The Choose an Amazon Machine Image (AMI) page displays a list of basic
configurations called Amazon Machine Images (AMIs) that serve as templates for your
instance. Select the HVM edition of the Amazon Linux AMI.
Step 8.3: Scroll down and select the key pair you created in the creating a key pair section
above or any existing key pair you intend to use.
• Select Select an existing security group.
• Select the WebServerSG security group that you created.
• Select Launch Instance.
11
Step 8.4: In the left-hand navigation bar, choose Instances to view the status of your
instance. Initially, the status of your instance is pending. After the status changes
to running, your instance is ready for use.
Step 9.2: Connect to Linux instance Using PuTTy, by means of IP address of each
instance.
Step 10: Completing the previous steps enables us to download and install Jenkins on AWS. To
12
download and install Jenkins:
Step 10.1: Ensure that your software packages are up to date on your instance by using the
following command to perform a quick software update:
[ec2-user ~]$sudo yum update –y
Step 10.2: Add the Jenkins repo using the following command:
[ec2-user ~]$sudowget -O /etc/yum.repos.d/jenkins.repo\https://pkg.jenkins.io/redhat-
stable/jenkins.repo
Step 10.3: Import a key file from Jenkins-CI to enable installation from the package:
[ec2-user ~]$sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io-2023.key
[ec2-user ~]$sudo yum upgrade
Step10.4: Install Java (Amazon Linux 2023):
[ec2-user ~]$sudodnf install java-17-amazon-corretto -y
Step 10.5: Install Jenkins:
[ec2-user ~]$sudo yum install jenkins -y
Step 10.6: Enable the Jenkins service to start at boot:
[ec2-user ~]$sudosystemctl enable Jenkins
Step 10.7: Start Jenkins as a service:
[ec2-user ~]$sudosystemctl start jenkins
RESULT:
Thus, the steps to install Jenkins in cloud has been written and completed successfully.
13
Ex. No: 4
CREATE CI PIPELINE USING JENKINS
Date:
AIM:
To implement a Continuous Integration (CI) pipeline with Jenkins to automate the build and test
processes for a Java project.
PROCEDURE:
Step 1: Install the required Jenkins Plugins: Install the necessary plugins in Jenkins, such as Git,
Maven.
Step 2: Configure Jenkins Credentials: Set up credentials in Jenkins for accessing your version
control system.
Step 3: Create a New Jenkins Job: Open Jenkins and create a new freestyle project or a pipeline
job.
Step 4: Configure Source Code Management: Choose the version control system (e.g., Git).
Step 6: Set Build Triggers: Configure triggers to initiate the build process automatically when
Step 7: Configure Build Steps: Define build steps based on your project requirements.
Step 9: Save and Run the Pipeline: Save the Jenkins job configuration.
Step 10: Manually trigger the job to ensure that it runs successfully.
Step 11: Integrate testing steps into the pipeline. For example, add additional Maven goals for
Step 12: Customize the pipeline according to the specific needs of the build process.
14
Screenshot:
15
2.Set Build Triggers:
16
4.Save and Run the Pipeline:
• Save the job configuration.
• Manually trigger the job and verify that the build process runs successfully.
17
18
OUTPUT:
RESULT:
Thus, creating a CI pipeline using Jenkins is executed and the output is verified successfully.
19
Ex. No: 5
CREATE A CD PIPELINE IN JENKINS AND DEPLOY IN CLOUD
Date:
AIM:
To implement a CD pipeline in Jenkins to automate the deployment of a Java application in AWS
cloud.
PROCEDURE:
Step 1: Launch Tomcat Server
• Enter the name “Tomcat-Server”
• Choose the Amazon Linux AMI.
• Select the size of the instance t3. micro or anything that lies in the free tier.
• Let's create a key pair for your instance, naming it 'Tomcat-Key' and download it.
• Choose “Tomcat-Security-Group”
Step 2: Connect to the Tomcat Server using SSH
Connect to it through SSH, following the same steps as followed in the Jenkins server by
clicking on “Connect”.
Step 3: Install Tomcat on your Instance
• Move to the opt directory and download the tomcat package
cd /opt
sudo wget https://downloads.apache.org/tomcat/tomcat-8/v8.5.85/bin/apache-
tomcat-8.5.85.tar.gz.asc
• Now we have to unzip and untar the package with a single command, i.e.
sudo tar -xvzf apache-tomcat-8.5.85.tar.gz
• Move into the file "apache-tomcat-8.5.85.tar.gz"
• Now move to the bin folder
• Now the “startup.sh” is used for starting the tomcat server and “shutdown.sh” for
shutting down.
Step 4: Add tomcat credentials to Jenkins
• Go to Manage Jenkins>Manage Credentials
• Click on “global Credentials” and then “Add Credentials”
• We added a user with a role in tomcat
• Add the username and password as given and then create.
20
Step 5: Create a Job for deploying the Maven Project
• Click on “create a job”.
• Here is the GitHub Link to the project
• Fork the repo
• Enter a name for the project/job and select “maven project”
• In the Source Code Management, choose git and enter the repository URL, by
clicking on code
• Since all the code is in the master branch in the given project, we will use the
master branch.
• Under the build section, we usually give these three options, i.e., "clean install
package” with the pom.xml file already present there.
• pom.xml → It is an XML file that contains information about the project and
configuration details used by Maven to build the project
• Now choose the option “Deploy war/ear to a container”
• Next, we have to specify the path of the war file, or we can just write “**/*.war” so
that Jenkins will find the file having the type “.war” in that particular workspace.
• Now in the container section, choose tomcat with its latest version i.e., tomcat 9
• Also, choose the credentials from the dropdown that we just created, i.e., deployer
• Next, copy the URL of the tomcat server, on which you can access it from the
browser
21
• Now save and click on “Build Now”
22
• Now we can access our app on the browser by adding "/webapp" in the URL
RESULT:
Thus, the process to implement a CD pipeline in Jenkins to automate the deployment of a Java
application in AWS cloud has been done successfully.
23
Ex. No: 6
CREATE AN ANSIBLE PLAYBOOK FOR A SIMPLE WEB
Date: APPLICATION INFRASTRUCTURE
AIM:
To develop an Ansible playbook for a simple web application.
PROCEDURE:
Step 1: First create two servers, a host machine for your Ansible and a server on which Ansible
will be performed.
Step 2: On the newly created servers, download package information from all configured
sources.
sudo apt-update
Step 3: Install Ansible on the host server
sudo apt install ansible
Step 4: Create your public and private keys which will be used to access the web server from the
Ansible host. on the terminal run the command and follow the prompt to generate the ssh
keys.
ssh-keygen
Step 5: Copy the content of the public key from the host server into .ssh/authorized_keys file on
the web server.
Step 6: Use the command ssh and try to ping the web server.
Step 7: Create an inventory file and add the private IP of the web server and ping using Ansible.
ansible -i inventory webserver -m ping
Step 8: Create a playbook. A playbook is a file used to run tasks with Ansible.The playbook
below shows the differnt tasks that were executed.
The tasks include:
1. create a group
2. create a user
3. create a file
4. create a webfolder
5. install apache2
6. start apache service
24
7. install unzip
8. decompress a fil
copy the file into /var/www/html
- hosts: webserver become: true
tasks:
- name: Create Group
group:
name: testadmin
gid: 401
25
- name: Decompress the Downloaded file unarchive src:
https://github.com/inimitable/SwiggyClone/archive/refs/heads/master.zip
dest: /var/www/html
remote_src: true
- name: Copy downloaded content into /var/www/html
shell: |
cd /var/www/html && cp -r Swiggy-Clone-master/*/var/www/html/
Step 9: In the inventory file, paste the private ip address of your remote server.
[webserver]
ip address of your server
Step 10 : Run the ansible playbook
ansible-playbook -i inventory playbook.yaml
Step 11: Confirm the apache2 service is active and running
sudo systemctl status apache2.service
Step 12: Check the remote server to confirm that you have the folder in /var/www/html.
Step 13: Open your browser and type in the public ip of your server. We see a page similar to the
one below.
RESULT:
Thus, the sequential breakdown of the steps involved in creating an Ansible playbook for a simple
web application has been done and verified successfully.
26
Ex. No: 7
BUILD A SIMPLE APPLICATION USING GRADLE
Date:
AIM:
To build a simple Java application using Gradle.
PROCEDURE:
27
dependencies {
implementation 'org. slf4j: slf4j-api:1.7.32'
testImplementation 'junit:junit:4.13.2'
}
Output:
1. Ensure Java is installed on your system
2. Download and unzip/unpack the compressed file. In File Explorer, create a new
directory C:\Gradle (you can choose any path according to your choice)
28
3. Configure your system environment, To set the Environment variable, Open System properties and
choose Environment Variables.
In the section System Variables select Path, then select the Edit option.
29
Select New, then add an entry for C:\Gradle\bin as shown in the image, now click on
the OK button to save changes.
30
5. Gradle tasks can be written using Groovy code from inside a projects build.gradle file. These tasks
can then be executed using >gradle [taskname] at the terminal or by executing the task from within
an IDE such as Eclipse.
6. To create the Hello World example in gradle, define a task that will print a string to the console
using Groovy.
Source Code:
build.gradle
task helloWorld<< {
}
7. To execute this task by using >gradle hello or >gradle -q hello. The -q is used to suppress gradle log
messages so that only the output of the task will be shown.
Output:
>gradle -q helloWorld
Hello world!
31
RESULT:
Thus, building a simple Hello World Application using Gradle has been done and verified
successfully.
32
Ex. No: 8
INSTALL ANSIBLE AND CONFIGURE ANSIBLE ROLES AND TO
Date: WRITE PLAYBOOKS
AIM:
To install Ansible & configure App server environment with roles.
PROCEDURE:
Step 1: Install Ansible.
• configure httpd.conf
Role Structure:
mkdir -p ~/ansible/roles/your_role_name/{tasks,handlers,files,templates,vars,defaults,meta}
Output:
roles/
33
└── apache
├── defaults
│ └── main.yml
├── files
├── handlers
│ └── main.yml
├── meta
│ └── main.yml
├── README.md
├── tasks
│ └── main.yml
├── templates
├── tests
│ ├── inventory
│ └── test.yml
└── vars
└── main.yml
• Create three different tasks files, one for each phase of application lifecycle * Install
* Configure * Start Service.
• To install apache, Create roles/apache/tasks/install.yml
---
34
• To have these tasks being called, include them into main task.
• Edit roles/apache/tasks/main.yml
---
# tasks file for apache
- import_tasks: install.yml
- import_tasks: service.yml
Create a playbook for app servers app.yml with following contents
---
- hosts: app
become: true
roles:
- apache
35
192.168.61.13 : ok=3 changed=2 unreachable=0 failed=0
• Copy index.html and httpd.conf from chap6/helper to /roles/apache/files/ directory
cd chap6
cp helper/httpd.conf roles/apache/files/
• Create a task file at roles/apache/tasks/config.yml to copy the configuration file.
---
- name: copy over httpd configs
copy:
src: httpd.conf
dest: /etc/httpd.conf
owner: root
group: root
mode: 0644
• Update this file to send a notification to restart service on configuration update. You simply have to
add the line which starts with notify
---
copy:
src: httpd.conf
dest: /etc/httpd.conf
owner: root
group: root
mode: 0644
---
36
service: name=httpd state=restarted
---
---
- import_tasks: install.yml
- import_tasks: service.yml
- import_tasks: config.yml
• Apply and validate if the configuration file is being copied and service restarted.
ansible-playbook app.yml
RESULT:
Thus, the configuration to work with App server environment with roles was done and executed
successfully.
37
ADDITIONAL EXPERIMENT
38
Ex. No: 9
MODIFY AZURE – PIPELINES YAML FILE
Date:
AIM:
To modify pipeline .yaml file to check the CI/CD pipeline in Azure DevOps.
PROCEDURE:
39
Step 8: Now, go to azure cloud and click on the URL to get the output.
Step 9: Just edit index.jsp in our repository of azure DevOps.
RESULT:
Thus, the modification for pipeline .yaml file has been done to check the CI/CD pipeline and
verified successfully.
40