DEVOPS
DEVOPS
DEVOPS
Create CI pipeline
using Jenkins
5
Create a CD pipeline in
Jenkins and deploy in
Cloud
6 Create an Ansible
playbook for a simple
web application
infrastructure
7 Build a simple
application using
Gradle
8 Install Ansible and
configure ansible roles
and to write playbooks
112021104004
EX.NO:01
DATE: TO CREATE A MAVEN BUILD PIPELINE IN AZURE
AIM:
To create an maven bulid pipeline in azure for web application in an infrastructure
PREREQUISITES:
1. An Azure DevOps organization.
2. Create an organization, if you don't have one already.
3. Install Apache Maven.
4. An Azure Artifacts feed. Create a feed if you don't have one already.
PROCEDURE:
Step1: Create a new organization in Azure DevOps as below.
112021104004
112021104004
112021104004
Step 2. Once the organization is created, please go to the Marketplace and install the J Frog
azure devops extension as below.
112021104004
Step 3: As a next step create a project under the organization by clicking the new project button
as in the screenshot below and provide the name and its private or public project.
Step 4: Now we can create a pipeline by going to the pipelines. Please check the below
screenshot.
112021104004
Step 5: Create a new pipeline by clicking the new pipeline button. It will ask you to select
where your code is and all, basically the source code. Select GitHub or any SCM as your source
code provider and then select the repository name. Once you complete the authentication, it will
create a basic template.
112021104004
112021104004
112021104004
Step 6: We need to create the Artifactory and GitHub connections as below. These will be used
to authenticate Azure DevOps with Artifactory and also the maven which will be used in the
tasks.
In order to configure the JFrog extension and the GitHub, go to the service connections option and search
for JFrog and GitHub as below.
Select the JFrog Artifactory V2 for setting up Artifactory with Azure DevOps.
112021104004
For Artifactory, please fill in the following details and verify the connection. If it’s successful, save the
same.
112021104004
# Maven
# Build your Java project and run tests with Apache Maven.
# Add steps that analyze code, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/java
trigger:
- master
pool:
vmImage: ubuntu-latest
steps:
- task: Maven@4
inputs:
mavenPomFile: 'maven-examples/maven-example/pom.xml'
goals: 'clean deploy'
publishJUnitResults: true
testResultsFiles: '**/surefire-reports/TEST-*.xml'
javaHomeOption: 'JDKVersion'
mavenVersionOption: 'Default'
mavenAuthenticateFeed: true
112021104004
effectivePomSkip: false
sonarQubeRunAnalysis: false
- task: Bash@3
inputs:
targetType: 'inline'
script: 'env | sort'
- task: JFrogPublishBuildInfo@1
inputs:
artifactoryConnection: 'mk-jfrog-artifactory-hts'
buildName: '$(Build.DefinitionName)'
buildNumber: '$(Build.BuildNumber)'
Step 7: As a next step run the build by clicking the run button.
112021104004
Step 8. The “displayNames” are added manually as they are not generated by the task. This will show the
Display names of the Tasks. If not defined, it will show the name of the Tasks as the Display names.
This will push the build to the maven repository in Artifactory with the build info.
RESULT:
Thus the create an maven build pipeline in azure build successfully and verified it.
112021104004
Ex.No.02
RUN REGRESSION TESTS USING
Date: MAVEN BUILD PIPELINE IN AZURE
AIM :
PREREQUISITES:
To operate, Azure Pipeline relies on two types of agents:
Microsoft hosted: Agents are hosted on Microsoft Cloud and many platforms are offered.
Self hosted: You can download the agent installer and host it yourself on the environment of
your choice.
We use self-hosted agents and this is the solution that will be described here. However, it is
certainly possible to adapt the information below if you wish to use agents hosted on the
Microsoft Cloud
.
PROCEDURE:
You can install the Azure Pipeline agent on a Linux, MacOS, Windows or Docker machine.
To start, log in to Azure DevOps and click on User settings and then on Personal access
tokens:
112021104004
Create a new token by selecting the Agent Pools (read, manage) permission
Return to the Azure DevOps home page and click on Organization settings at the
bottom left.
Click on Agent Pools and select the Default pool or create a new Self hosted one.
Click on New Agent and follow the instructions on the page to upload your agent.
Unzip the downloaded archive on the machine where you want to install the agent and
run config.cmd.
Follow the script to set up your agent, including the token created earlier. When you
have the choice between an interactive mode or as a service, choose the interactive
mode otherwise you will not be able to launch the ATS tests.
Once your agent is configured, run run.cmd to start it.
Machine setup
Once the agent is installed, several elements are necessary for the proper functioning of the
ATS tests:
The .actiontestscript folder: this folder must be present at the root of the user's folder
that will run the agent. It is created automatically and updated when Agilitest is
launched. If you do not wish to install Agilitest on the machine where the agent is
installed, you can copy and paste this folder from another computer where Agilitest is
installed. In the future it will be possible to update this folder via npm and to
automated it in the pipeline.
The JDK must be installed. Currently Agilitest needs JDK version 11 or higher.
Maven must also be installed, you can download it here:
https://maven.apache.org/download.cgi
Step 3:Then click on New pipeline and indicate where your Agilitest project code is located
and follow the instructions to connect the Azure Pipeline to it.
Step 5:The selection of a maven project will allow AzuredevOps to directly manage the
dependencies and external required libraries.
You can also start from an empty pipeline and add a Maven task.
In the pool section, change the "vmImage" type to "name" and enter the name of the pool you
created earlier.
Step 7 :If you click on Save and run, the YAML file will be added to your source code and
your tests will be run according to the configuration in your pom.xml file.
112021104004
RESULT:
Thus ,to run regression tests using Maven Build pipeline in Azure is executed
successfully.
112021104004
EX.NO:03
INSTALL JENKINS IN CLOUD
DATE:
AIM:
PRE-REQUISITES:
There are certain pre-requisites to have Jenkins up and running in your system:
PROCEDURE :
5. If you haven't previously used Cloud Shell, configure the environment and storage
settings.
6. Select the command-line environment.
JSONCopy
112021104004
#cloud-config
package_upgrade: true
runcmd:
- sudo apt install openjdk-11-jre -y
- curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key | sudo tee
/usr/share/keyrings/jenkins-keyring.asc > /dev/null
- echo 'deb [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
- sudo apt-get update && sudo apt-get install jenkins -y
- sudo service jenkins restart
Azure CLICopy
Azure CLICopy
az vm create \
--resource-group jenkins-get-started-rg \
--name jenkins-get-started-vm \
--image UbuntuLTS \
--admin-username "azureuser" \
--generate-ssh-keys \
--public-ip-sku Standard \
--custom-data cloud-init-jenkins.txt
7. Run az vm list to verify the creation (and state) of the new virtual machine.
Azure CLICopy
8. As Jenkins runs on port 8080, run az vm open to open port 8080 on the new virtual
machine.
Azure CLICopy
az vm open-port \
--resource-group jenkins-get-started-rg \
--name jenkins-get-started-vm \
112021104004
Azure CLICopy
az vm show \
--resource-group jenkins-get-started-rg \
--name jenkins-get-started-vm -d \
--query [publicIps] \
--output tsv
Key points:
The --query parameter limits the output to the public IP addresses for the virtual
machine.
Using the IP address retrieved in the previous step, SSH into the virtual machine. You'll
need to confirm the connection request.
Azure CLICopy
ssh azureuser@<ip_address>
Key points:
Upon successful connection, the Cloud Shell prompt includes the user name and
virtual machine name: azureuser@jenkins-get-started-vm.
Verify that Jenkins is running by getting the status of the Jenkins service.
BashCopy
Key points:
If you receive an error regarding the service not existing, you may have to wait a
couple of minutes for everything to install and initialize.
Get the autogenerated Jenkins password.
BashCopy
In the filter box at the top of the page, enter github. Select the GitHub plug-in and
select Install.
Enter the information for the first admin user and select Save and Continue.
2. Enter a job name of mySampleApp, select Freestyle project, and select OK.
3. Select the Source Code Management tab. Enable Git and enter the following URL for
the Repository URL value: https://github.com/spring-guides/gs-spring-boot.git. Then
change the Branch Specifier to */main.
112021104004
7. Select Advanced and enter complete in the Root Build script field.
112021104004
1. When the home page for your project displays, select Build Now to compile the code and
package the sample app.
112021104004
2. A graphic below the Build History heading indicates that the job is being built.
4. Navigate to complete/build/libs to see that the .jar file was successfully built.
5. Your Jenkins server is now ready to build your own projects in Azure!
RESULT:
Thus Installating Jenkins in Cloud platform is created successfully.
112021104004
EX NO: 4
CREATE A CI PIPELINE USING JENKINS
DATE:
AIM:
PREREQUESITES:
Step 1) Copy your public IP address from your virtual machine in Azure, as shown in the
image below.
Step 2) We have already added port number 8080 in the previous steps while preparing our
system.
PROCEDURE:
Step 1:
Create New Item, select Freestyle
Step 2:
112021104004
Switch to the Source Code Management window and paste your Github repository link.
Specify your branch nameof the repository below and Save it.
Step 3:
Now click on Build Now button from the menu. With this step, all the repository files will be
fetched by Jenkins. Click on Configure to go back to the same settings page.
Step 4:
Click on Build Tab and select build step as ‘Invoke top-level Maven targets‘.
112021104004
Step 5:
Select your maven name from the drop-down menu. Fill the goals with the multiple jobs you
need to perform and separate them with one space. These goals are available in your repository,
and you need to invoke them using Maven. Save it and again click on the ‘Build Now‘ button
from the menu as we did in the previous steps. Now the maven commands will be executed that
will generate a war file.
Step 6:
If you want to check the war file created in the previous steps, visit the workspace on your
Jenkins dashboard or just run the directory commands in your server. Your directories and
project name can vary, so you can use the ‘ls‘ commandto see the list inside that directory and
also keep in mindthe directory name is case sensitive.
cd /var/lib/jenkins/workspace/
ls
cd /Demo
cd /webapp/target
Step 7:
112021104004
Now go back to Configure and visit the ‘Post Build Actions‘ tab. Click the drop-down and select
‘Archive the Artifacts‘ from the options. In the field, write down ‘**/*.war‘ as shown in the
image below. It will fetch all the directories and get the war file wherever it is present. Click
again on Build Now button, and you will now see the Artifacts in the Jenkins dashboard.
RESULT:
Thus the creation of CI pipeline using jenkins was verified and executed successfully.
112021104004
EX NO:05
CREATE A CD PIPELINE IN JENKINS AND DEPLOY
DATE: IN CLOUD
AIM:
PREREQUESITES:
*We have already added port number 8080 in the previous steps while preparing our
system
PROCEDURE
Step 1:
We need to install Apache Tomcat, and for this, you need to visit the Tomcat
Download page. In the core section, hover over the ‘tar.gz’ link and copy it. Now, use the below
commands in your server one by one.
First, four commands will create one temporary directory and user group to access the
file. Here, use the command curl -O ‘paste tomcat download link‘ as shown in the
command below.
Use further commands to create a tomcat directory and extract the gzip file. Just cross-
check the version number of the Tomcat that you are downloading and extracting.
Now the permission of the files needs to be configured with the below commands. In the
last command, replace it with your username by which you are accessing the server.
curl -O https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.54/bin/apache-tomcat-9.0.54.tar.gz
sudo mkdir /opt/tomcat
sudo tar xzvf apache-tomcat-9.0.54.tar.gz -C /opt/tomcat --strip-components=1
112021104004
cd /opt/tomcat
sudo chgrp -R tomcat /opt/tomcat
sudo chmod -R g+r conf
sudo chmod g+x conf
cd ..
sudo chown -R jenkinsuser:jenkinsuser tomcat/
Step 2:
We need to update the port number from 8080 to 8090 in the server.xml file. We are
updating it as this port number is already in use by Jenkins, and we have created 8090 in Azure
VM for Tomcat. Use the below commands to edit the file. When you enter the file, click
the INSERT button to edit. Now search for a similar code, as shown in the image below. Update
the port number to 8090. To save the file, press the Esc key, type :wq and click on Enter button.
cd
cd /opt/tomcat/conf
vi server.xml
Step 3:
Similarly, we need to edit the ‘tomcat-users.xml’ file to update the roles that enable us to
deploy files using Tomcat. In the file before tomcat-users ending code, paste the below roles
code. To save the file press, the Esc key, type :wq and press Enter.
cd
cd /opt/tomcat/conf
vi tomcat-users.xml
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<role rolename="manager-jmx"/>
<role rolename="manager-status"/>
<user username="admin" password="admin" roles="manager-gui, manager-script, manager-
jmx, manager-status"/>
<user username="deployer" password="deployer" roles="manager-script"/>
<user username="tomcat" password="s3cret" roles="manager-gui"/>
112021104004
Step 4:
We also need to update the context.xml file to remove the IP restriction. Use the same
steps to edit the file with the below commands. Remove all the content present inside ‘context‘
as shown in the image below and save it.
cd
cd /opt/tomcat/webapps/manager/META-INF
vi context.xml
Step 5:
Now, all the files are edited successfully. To update the Tomcat, we need to restart the
system to accept all our changes. Use the below commands in the server for shutdown and
startup of Tomcat. With this step, Tomcat is ready to deploy our container.
cd
cd /opt/tomcat/bin/
./shutdown.sh
./startup.sh
Step 6:
In the Jenkins Dashboard, click on Manage Jenkins and then visit Manage Plugins.
112021104004
Step 7:
Click on the Available tab and search for the ‘Deploy to Container‘ plugin. Select the
plugin and click on the ‘Install without restart‘ button
Step 8:
Go back to your Configure window and select the Post-build Actions tab. Select the ‘Add
post-build action‘ drop-down button and select the ‘Deploy war/ear to a container‘ plugin. Fill
the same path of your war file here, as shown in the image below.
112021104004
Step 9:
Now click on the ‘Add Container‘ button and select the ‘Tomcat 9.x Remote‘ as we are
using version 9 of the Tomcat. Fill in the URL of the same virtual machine with the new port
number 8090. On the credentials drop-down button, select Jenkins
Step 10:
In this window, fill in the username and password that we have used in the ‘tomcat-
users.xml‘ file (in Step 10). Fill in the ID, description and click on the button ‘Add‘.
112021104004
Step 11:
Click on the credentials drop-down button and select the recently created credential.
Save all the settings and again click on the ‘Build Now‘ button from the Jenkins dashboard. If the
Build is successful, the war file will get deployed.
112021104004
Step12:
Visit the address of your virtual machine, and you will see your deployment on the page. In our
case, the URL is ‘52.139.207.89:8090/webapp/‘ with port number 8090 that we created for
Tomcat.
RESULT:
Thus the program create a cd pipeline and deploy a cloud is executed successfully
112021104004
AIM:
PREREQUISITES :
Some basic knowledge is assumed in this tutorial for the sake of brevity.
Among it is:
PROCEDURE:
Step 1:
First let’s create our fleet of EC2 instances. Head over to the AWS console and create 3 EC2
instances in your region of choice; I’m using the free tier Red Hat AMI (Red Hat Enterprise
Linux 9 (HVM) SSD Volume Type). Keep the default “x86” architecture and select t2.micro for
instance type. For your security group inbound rules you need SSH access from your IP, access
to port 80 from the internet (0.0.0.0/0), and all traffic from your VPC. You’ll also need an
outbound rule for all traffic to the internet. For instance name, write “ansible” for now. In a
minute we’ll go in and change each instance name individually.
112021104004
Step 2:Once the instances have been created, on the right side of each instance name you can
click the little pencil icon to change the name. Name them something similar to what I’ve done,
where each one is assigned a number.
Furthermore, you can also change the hostname of each instance in the terminal as well.
SSH into each instance and use the following command to set the hostname:
sudo hostnamectl set-hostname <new_host_name>
Your instance will stop and you will be kicked out. After a few moments you should be
able to SSH back in and see the change.
112021104004
Step 3: Let’s create a Git repository for this project. Go to GitHub and create the repository.
Name it whatever you’d like. I called mine “ansible_basics”. Then clone it to your local
machine.
You will be informed that you have cloned an empty repository, which is ok because we
haven’t added anything to it yet.
It’s also good practice to use another branch besides “main” for development. I typically
just create a branch called “dev” to write my code in. To create a new branch use:
Then switch into the new branch with the git checkout command:
When you’re ready to push changes to your remote repository you can use:
Branch name would be the branch you are working in, not main. Once you push, you can
create a pull request on GitHub to merge that branch into main. This is how a workflow
would look in a typical development environment.
112021104004
Step 4:
Once we have our git repository set up we’ll need to install Ansible on our local machine.
The easiest way of installing Ansible on a Mac is to use.
If you don’t use Mac or you need another way to install Ansible, you can check out this
page for the best way for you to install it.
You can also check your version of python by using:
python --version
112021104004
or
python3 --version
When python3 is installed there should be a symlink created so that anything simply
referencing python will be redirected to the python3 version.
python --version
RESULT:
Thus the ansible playbook for a simple web application infrastructure was created
successfully.
112021104004
Ex.No:7
BUILD A SIMPLE APPLICATION USING GRADLE
Date:
AIM:
To build a simple application using gradle
PREREQUISITES:
PROCEDURE:
Step1:
The first step is creating a directory for a new project and change directory to it.
1. mkdir java_application
Follow the below command to change the command line directory to it:
1. cd Java_application
1.
gradle init
Step3: Select the project type that you want to generate. There are four command-line options
available, which are as follows:
1. basic
112021104004
2. application
3. library
4. Gradle plugin
Type 2 and press enter key to create an application. The default selection is basic.
Step 4: Select the implementation language. There are five options available, which are as
follows:
1. C++
2. Groovy
3. Java
4. Kotlin
5. Swift
Type 3 and press Enter key for Java. The default selection is Java.
Step 5: The next step is to select the default build script language for the project. There are two
options available, which are as follows:
1. Groovy
2. Kotlin
Type 1 and press Enter key for Groovy. The default selection is Groovy.
Step6: Select the test framework. There are four options available for the testing framework.
They are as follows:
1. JUnit 4
2. TestNG
3. Spock
4. JUnit Jupiter
Step7: Enter the project name; by default it will take the directory name as the project name.
Step8: Enter the source package; by default it will take the directory name as a source package.
112021104004
Now the init task is successfully executed, and we have created a Java application using Gradle
Init API.
Generated files:
gradle:
112021104004
It is heavily commented and has only one active line. It sets the name of the root project.
1. rootProject.name = 'Java_application'
It will use the default behavior of naming the project after the directory in which it is available. It
looks like:
gradle:
It is the build script of the Gradle project. The generated build.gradle file has many components.
The used dependencies and their versions are introduced in this build script. The content of the
generated build file is as follows:
1. plugins {
2. id 'java'
3. id 'application'
4. }
5. repositories {
6. jcenter() //public bintray artifactory repository
7. }
8. dependencies {
9. implementation 'com.google.guava:guava:27.1-jre' //Google Guava Library
10. testImplementation 'junit:junit:4.12' //JUnit testing library
11. }
12. application {
13. mainClassName = 'Java_application.App' // class with the main method used by Gradle plugin
14. }
112021104004
The Gradle build script adds the Java and application plugins. When we run a gradle command,
it will search in Gradle's build script.
java:
Gradle supports Java projects and contains a class that having the main method, which can be
executed from the command line. In the Java_Application, the name of the main class is App.
1. package Java_application;
2. public class App {
3. public String getGreeting() {
4. return "Hello world.";
5. }
6. public static void main(String[] args) {
7. System.out.println(new App().getGreeting());
8. }
9. }
Java:
It is the test class of the Java project. The test class takes place in the
directory Java_application\src\test\java\Java_application. The generated code of the
AppTest.java is as following:
1. package Java_application;
2. import org.junit.Test;
3. import static org.junit.Assert.*;
4. public class AppTest {
5. @Test public void testAppHasAGreeting() {
6. App classUnderTest = new App();
7. assertNotNull("app should have a greeting", classUnderTest.getGreeting());
8. }
9. }
112021104004
The init task generates the given Java test file. The generated test file contains a single test
annotated with @test annotation of JUnit. This test instantiates the App class, invokes
the getGreeting(), and checks that the returned value is not null.
To execute a gradle build, run the build task along with gradlew command. However, we can run
the gradle task, but it is good to include the wrapper script.
1. gradlew build :
Output:
The build task compiles the classes, runs the tests, and creates the test reports.
Note: The first time we run the gradlew command, it may take some time, while the specified version
of gradle is downloaded and stored locally.
The Gradle wrapper script checks whether we have specified the Guava and JUnit libraries or
not, if not, then it will download and store it in the /.gradle directory.
The gradle build uses the application plugin so we can run the application from the command
line. The gradlew run command will be used to run the application from the command line.
First, use the task command to display the added tasks by the plugin:
1. gradlew tasks :
The above command will list the available tasks in the project. consider the below snap
of Output:
112021104004
Now, run the application by using the run command. It will convey Gradle to execute the main
method in the class assigned to the mainClassName property.
1. gradlew run :
Output:
Hello world.
RESULT:
Thus the build a simple application using gradle was created successfully.
112021104004
Ex.No:08
INSTALL ANSIBLE AND CONFIGURE ANSIBLE
Date:
ROLES AND TO WRITE PLAYBOOKS
AIM:
PREREQUISITES:
The Ubuntu 18.04 OS installed on your system or a later version of this OS.
Sudo access or root privileges.
Internet connectivity to download Ansible packages.
Python 2.7 or Python 3.5 or later installed.
PROCEDURE:
Step 1: Connect to Your Soon-to-Be Ansible Controller
You can make this connection using your favorite Secure Socket Shell (SSH) client. With
Ubuntu, you use Terminal to establish a secure connection to your host.
Any time you are installing new software, it is a good idea to ensure your existing operating
system software is up to date. Let's start with that task first.Use the command below to update
the package lists. This command will update the local package lists on your Ubuntu system to
ensure that you have the latest information about available software packages:
This step is necessary for managing software repositories. Run the following command to
install the software-properties-common package:
It must be added as an apt repository. Run the command below to add it. This command adds the
Ansible PPA as a software repository, allowing you to install Ansible through the apt package manager:
112021104004
After the installation is complete, you need to verify that Ansible is installed by running the following
command:
ansible --version
When you run the above command, it will display the version information for Ansible on your Ubuntu
system. If Ansible has been installed successfully, you should see the version number along with other
details. If you don't get this information, then you might have done something wrong along the way.
Simply revisit all the steps to ensure they were well executed.
where, ansible-glaxy is the command to create the roles using the templates.init is to initiliaze the
role.apache is the name of role,offline - create offline mode rather than getting from online
repository.
RESULT:
Thus the ansible and ansible roles was installed and configured successfully.