Dev Ops
Dev Ops
NO:01
TO CREATE A MAVEN BUILD PIPELINE IN AZURE
DATE:
AIM:
To create an maven bulid pipeline in azure for web application
in an infrastructure
PROCEDURE:
Step1: Create a new organization in Azure DevOps as below.
Step 2. Once the organization is created, please go to the Marketplace and install
the J Frog azure devops extension as below.
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.
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.
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.
# Maven
# Build your Java project and run tests with Apache Maven.
# Add steps that analyze code, save build artifacts, deploy, and more:
# [Link]
trigger:
- master
pool:
vmImage: ubuntu-latest
steps:
- task: Maven@4
inputs:
mavenPomFile: 'maven-examples/maven-example/[Link]'
goals: 'clean deploy'
publishJUnitResults: true
testResultsFiles: '**/surefire-reports/TEST-*.xml'
javaHomeOption: 'JDKVersion'
mavenVersionOption: 'Default'
mavenAuthenticateFeed: true
effectivePomSkip: false
sonarQubeRunAnalysis: false
- task: Bash@3
inputs:
targetType: 'inline'
script: 'env | sort'
- task: JFrogPublishBuildInfo@1
inputs:
artifactoryConnection: 'mk-jfrog-artifactory-hts'
buildName: '$([Link])'
buildNumber: '$([Link])'
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. For
Artifactory, please fill in the following details and verify the connection. If
it’s successful, save the same.
Step 7: As a next step run the build by clicking the run button.
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.
[Link].02
RUN REGRESSION TESTS USING MAVEN
Date:
BUILD PIPELINE IN AZURE
AIM :
To run regression tests using maven build pipeline in azure.
You can install the Azure Pipeline agent on a Linux, MacOS, Windows or Docker
To start, log in to Azure DevOps and click on User settings and then on Personal
access tokens:
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 [Link].
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 [Link] to start it.
Machine setup
Once the agent is installed, several elements are necessary for the proper
functioning of the ATS tests:
Step 5:The selection of a maven project will allow AzuredevOps to directly manage
thedependencies 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 [Link]
file.
RESULT:
Thus ,to run regression tests using Maven Build pipeline in Azure is
executed successfully.
[Link]
INSTALL JENKINS IN CLOUD
DATE:
AIM:
PROCEDURE :
1. If you already have a Cloud Shell session open, you can skip to the next section.
2. Browse to the Azure portal
3. If necessary, log in to your Azure subscription and change the Azure directory.
4. Open Cloud Shell.
5. If you haven't previously used Cloud Shell, configure the environment
and storagesettings.
6. Select the command-line environment.
Step 3: Create a virtual machine
new file:JSONCopy
#cloud-config
package_upgrade:
trueruncmd:
- sudo apt install openjdk-11-jre -y
- curl -fsSL [Link] | sudo tee
/usr/share/keyrings/[Link] > /dev/null
- echo 'deb [signed-by=/usr/share/keyrings/[Link]]
[Link] binary/' | sudo tee
/etc/apt/[Link].d/[Link] >
/dev/null
- sudo apt-get update && sudo apt-get install jenkins -y
- sudo service jenkins restart
Azure CLICopy
az group create --name jenkins-get-started-rg --location eastus
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 [Link]
Run az vm list to verify the creation (and state) of the new virtual machine.
Azure CLICopy
az vm list -d -o table --query "[?name=='jenkins-get-started-vm']"
1. Run az vm show to get the public IP address for the sample virtual machine.
Azure CLICopy
az vm show \
--resource-group jenkins-get-started-rg \
--name jenkins-get-started-vm -d \
--query [publicIps] \
--output tsv
Key points:
Azure CLICopy
ssh azureuser@<ip_address>
Key points:
Key points:
If you receive an error regarding the service not existing, you may
have to wait acouple of minutes for everything to install and
initialize.
Get the autogenerated Jenkins password.
BashCopy
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
Using the IP address, open the following URL in a browser: [Link]
Enter the password you retrieved earlier and select Cont
Select Select plug-in to install.
In the filter box at the top of the page, enter github. Select the
GitHub plug-in andselect Install.
Enter the information for the first admin user and select Save and Continue.
On the Instance Configuration page, select Save and Finish.
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 forthe Repository URL value: [Link]
[Link]. Then change the Branch Specifier to */main.
1. When the home page for your project displays, select Build Now to
compile the code andpackage the sample app.
1. A graphic below the Build History heading indicates that the job is being built.
3. Navigate to complete/build/libs to see that the .jar file was successfully built.
Your Jenkins server is now ready to build your own projects in Azur
RESULT:
AIM:
PROCEDURE:
Step 1:
Step 2:
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‘.
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/workspac
e/ ls
cd /Demo
cd /webapp/target
Step 7:
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.
EX NO:05
CREATE A CD PIPELINE IN JENKINS AND DEPLOYIN CLOUD
DATE:
AIM:
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 ‘[Link]’ link and copy it. Now,
use the belowcommands in your server one by one.
First, four commands will create one temporary directory and user
group to access thefile. 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 thelast command, replace it with your username by which
you are accessing the server.
curl -O [Link]
[Link] mkdir /opt/tomcat
sudo tar xzvf [Link] -C /opt/tomcat --strip-components=1
cd /opt/tomcat
sudo chgrp -R tomcat
/opt/tomcatsudo chmod -R
g+r conf
sudo chmod g+x
confcd ..
sudo chown -R jenkinsuser:jenkinsuser tomcat/
Step 2:
We need to update the port number from 8080 to 8090 in the [Link]
file. We are updating it as this port number is already in use by Jenkins, and we
have created 8090 in AzureVM 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. Updatethe port number to 8090. To save the file, press the Esc key, type
:wq and click on Enter button.
cd
cd
/opt/tomcat/co
nfvi [Link]
Step 3:
Similarly, we need to edit the ‘[Link]’ file to update the roles
that enable us todeploy 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/co
nfvi tomcat-
[Link]
<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"/>
Step 4:
We also need to update the [Link] 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/MET
A-INFvi [Link]
Step 5:
Now, all the files are edited successfully. To update the Tomcat, we need
to restart thesystem 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/
./[Link]
./[Link]
Step 6
In the Jenkins Dashboard, click on Manage Jenkins and then visit
Manage Plugins.
Step 7:
Click on the Available tab and search for the ‘Deploy to Container‘
plugin. Select theplugin 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 ‘Addpost-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.
Step 9:
Now click on the ‘Add Container‘ button and select the ‘Tomcat 9.x
Remote‘ as we areusing 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 ‘[Link]‘ file (in Step 10). Fill in the ID, description and click on the
button ‘Add‘.
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 theBuild is successful, the war file will get deployed.
Step12:
Visit the address of your virtual machine, and you will see your deployment on
the page. In ourcase, the URL is ‘[Link]: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
[Link] CREATE AN ANSIBLE PLAYBOOK FOR A SIMPLE WEB
APPLICATION INFRASTUCTURE
Date:
AIM:
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 [Link] forinstance type. For your security group
inbound rules you need SSH access from your IP, access to port 80 from the
internet ([Link]/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.
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:
take effect.
I would recommend naming them something like “Ansible(1,2,3)” or
“AnsibleServer(1,2,3)”. Make sure you are naming with the number that
corresponds with the number you used when naming the instance
[Link] you have set the nameyou need to reboot for the name to
sudo hostnamectl set-hostname <new_host_name>
sudo reboot
Your instance will stop and you will be kicked out. After a few moments you
should beable to SSH back in and see the change.
Step 3: Let’s create a Git repository for this project. Go to GitHub and create
the [Link] 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 wehaven’t added anything to it yet.
It’s also good practice to use another branch besides “main” for
development. I typicallyjust 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 cancreate a pull request on GitHub to merge that branch into
main. This is how a workflow would look in a typical development
environmen
Step 4:
Once we have our git repository set up we’ll need to install Ansible on our
local [Link] easiest way of installing Ansible on a Mac is to use.
or
python3 --version
If you don’t use Mac or you need another way to install Ansible, you can check out
thispage for the best way for you to install it.
You can also check your version of python by using:
python --version
python --version
RESULT:
AIM:
To build a simple application using gradle
PROCEDURE:
Step1:
The first step is creating a directory for a new project and change
directory to it. Follow the below command to create a directory called
Java_application:
mkdir java_application
Follow the below command to change the command line directory to it:
cd Java_application
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
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
Enter your choice. The default selection is JUnit 4.
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.
Now the init task is successfully executed, and we have created a Java application
using Gradle Init API.
Consider the below output:
Generated files:
Let's have a look at the generated files of the project.
It is heavily commented and has only one active line. It sets the name of the root
project.
1. [Link] = '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 [Link] 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 '[Link]: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
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. [Link](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
[Link] is as following:
1. package Java_application;
2. import [Link];
4. import static [Link].*;
5. public class AppTest {
6. @Test public void testAppHasAGreeting() {
7. App classUnderTest = new App();
8. assertNotNull("app should have a greeting", [Link]());8.
}
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, invokesthe 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
versionof 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:
Output:
Hello world.
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 :
RESULT:
Thus the build a simple application using gradle was created successfully.
[Link]
INSTALL ANSIBLE AND CONFIGURE ANSIBLE ROLES
Date:
AND TO WRITE PLAYBOOKS
AIM:
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
[Link] 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 instal
sudo apt-add-repository --yes --update ppa:ansible/ansible
ansible --version
When you run the above command, it will display the version information
for Ansible on your Ubuntusystem. 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
[Link] is to initiliaze [Link] 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.