Devops Manual

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 37

PRINCE DR K.

VASUDEVAN COLLEGE OF

ENGINEERING AND TECHNOLOGY, PONMAR

CHENNAI-600 127.

DEPARTMENT OF

ARTIFICIAL INTELLIGENCE AND DATA SCIENCE

(B. Tech- VI SEMESTER)

SB 8050 - NAAN MUDHALVAN


DEVOPS
2023-2024

NAME :

REGISTE NO :

SEMESTER :

BRANCH :
INDEX

S.NO DATE EXPERIMENT TITLE PAGE NO SIGNATURE

1. INSTALL GIT ON WINDOWS AND BASIC


GIT COMMAND

2. HOW TO INSTALL THE JENKINS IN


WINDOWS

3. HOW TO CREATE A NEW JOB IN JENKINS

4. HOW TO INTEGRATE JENKINS IN


GITHUB

5. HOW TO DO THE JENKINS


MAVENCONFIGURATION
EX.NO:1 INSTALL GIT ON WINDOWS AND BASIC GIT COMMAND

DATE:

AIM:

To install git on windows command line and the basic git command.

THEORY:

Git is an open-source and free, decentralized version control system designed to handle projects
of all sizes with speed and efficiency. Basically, it is a software tracking application that is
commonly used to monitor projects across several teams. The best way of downloading and
installing Git on the windows command line is to download it from its official site.
PROCEDURE:

Steps to download and install Git on Windows

Step 1: Go to the official website: https://git-scm.com


Step 2: Click on 64-bit Git for Windows Setup and allow the download to complete.
Official-site-of-git

Extract and Launch Git Installer


Step 3: Go to your download location and double-click the file to launch the installer.
Step 4: Allow the app to modify your device by selecting Yes in the User Account Control
window that appears.
Step 5: Check the GNU General Public License and click Next Checking-GNU.

Step 6: Select the install location. If you don’t have a reason to modify it, leave it to default
and click Next.

Step 7: A screen for component selection will display. Leave the settings as it is and click

Next.
Step 8: The installer asks you to create a start menu folder. Simply click Next.

Step 9: Choose the text editor you want to use with Git and click Next.

Step 10: The following step allows you to give your original branch a new name. ‘Master’ is
the default. Leave the default choice selected and press the Next button.
Step 11: You can adjust the PATH environment during this installation phase. When you run
a command from the command line, the PATH is the default set of folders that are included.
Continue by selecting the middle (recommended) option and clicking Next.

Step 12: The following option concerns server certificates. The default choice is used by the
majority of users. Simply click Next.

Step 13: This step deals with how data is structured, and altering this option may create
issues. So, it is advised to leave the default selection.
Step 14: Select the terminal emulator that you wish to use. Because of its features, the default
MinTTY is suggested. Click Next.

Step 15: The installer now prompts you to specify what the git pull command should perform.
Leave the default selected option and click Next.

Step 16: The next step is to decide which credential helper to employ. Credential helpers are
used by Git to retrieve or save credentials. Leave the default selection and click Next.
Step 17: Although the default choices are suggested, this step allows you to select which
additional features to activate.

Step 18: Git offers to install some experimental features. Leave them unchecked and click
Install.

Step 19: Once the installation is complete, launch the Git bash.
After installing we need to configure the git. After configuration, we can only use it. git config
command helps users to do so.
Name and Email Setup
One of the first things that you will do is to set up your name and email address without this
you cannot even perform any commit operation.
The below codes will help us do so
$ git config --global user.name "Satyajit Ghosh"
$ git config --global user.email satya@example.com
Here is the terminal shell pictorial depiction after executing the above commands as follows:

Default Editor Setup


There are times when git needs a text editor to take input from the user like merge conflict or
renaming a commit etc. In those situations, git uses the default text editor of the system
generally the Emacs. As per your preference, you may want to use any other text editor, you
can do so by using git config.
Let’s suppose you want to make Visual studio code, your default text editor for the git. Then
we need to use the following command
git config --global core.editor code
Here is the terminal shell pictorial depiction after executing the above command:

Now, whenever git requires to open a text editor it will open the Visual Studio Code.
Default Branch Name
Git uses “master” as its default branch name, we can change it to any other name using the git
config command. Let’s suppose we want to make our default branch name “main” then we
can use the following command –
git config --global init.defaultBranch main
Now if you want to see all the changes you have made so far using git config, you can do that
using the following command as follows:
git config --list
Here is the terminal shell pictorial depiction after executing the above command:
if you want to learn more about the git config command then you try the below command in
the terminal
git config --help
This will show you all the available flags of the git config command along with the
documentation as depicted by the below terminal output as follows:
BASIC GIT COMMANDS ALONG WITH EXPLANATIONS FOR EACH:

1. git init
- Explanation: Initializes a new Git repository either in the current directory or in a
specified directory if provided. Creates a hidden `.git` directory that contains all the necessary
files for version control.

2. git clone [repository_URL]


- Explanation: Clones a remote repository from a specified URL to your local machine.
This creates a local copy of the repository, including all branches and commit history.

3. git add [file(s)]


- Explanation: Adds file(s) to the staging area, preparing them to be included in the next
commit. You can specify individual files, directories, or wildcards.

4. git status
- Explanation: Displays the current status of the working directory and the staging area. It
shows which files are modified, staged, or untracked.

5. git commit -m "[commit_message]"


- Explanation: Records changes to the repository. Commits all staged changes with a brief
commit message describing the changes made in this commit.

6. git push [remote_name] [branch_name]


- Explanation: Pushes committed changes from your local branch to a remote repository.
The `[remote_name]` is typically "origin" by default, and `[branch_name]` is the branch you
want to push.

7. git pull [remote_name] [branch_name]


- Explanation: Fetches changes from a remote repository and merges them into the current
branch. It's a combination of `git fetch` and `git merge`.

8. git fetch [remote_name]


- Explanation: Downloads objects and refs from another repository. Fetching allows you to
see what changes others have made to the remote repository without merging them into your
local branches.
9. git merge [branch_name]
- Explanation: Merges the specified branch into the current branch. It integrates changes
from another branch into your current branch.

10. git branch


- Explanation: Lists all local branches in the repository. By default, it shows the current
branch and indicates it with an asterisk (*).

11. git checkout [branch_name]


- Explanation: Switches to the specified branch. It updates the working directory to reflect
the selected branch's most recent commit.

12. git remote -v


- Explanation: Lists all the remote repositories configured for the current local repository
along with their URLs.

RESULT:
Thus, we install git on windows command line and the basic git command.
EX.NO:2 HOW TO INSTALL THE JENKINS IN WINDOWS

DATE:

AIM:

To install the Jenkins in the windows.

PROCEDURE:

How to Download Jenkins


Following steps should be followed so that to install Jenkins successfully:
Step 1) Got to https://www.jenkins.io/download/ and select the platform. In our case
Windows

Step 2) Go to download location from local computer and unzip the downloaded package.
Double-click on unzipped jenkins.msi. You can also Jenkin using a WAR (Web
application ARchive) but that is not recommended.

Step 3) In the Jenkin Setup screen, click Next.


Step 4) Choose the location where you want to have the Jenkins instance installed (default
location is C:\Program Files (x86)\Jenkins), then click on Next button.

Step 5) Click on the Install button.


Step 6) Once install is complete, click Finish.

Step 7) During the installation process an info panel may pop-up to inform the user that for a
complete setup, the system should be rebooted at the end of the current installation.
Click on OK button when the Info panel is popping-up:

How to Unblock Jenkins?


After completing the Jenkins installation phase, you should proceed further and start its
configuration. Next steps will guide you how you can unblock Jenkins application:
Step 1) After completing the Jenkins installation process, a browser tab will pop-up asking
for the initial Administrator password. To access Jenkins, you need to go to browse
the following path in your web browser.http://localhost:8080
If you can access the above URL, then it confirms that Jenkins is successfully installed in
your system.
Step 2) The initial Administrator password should be found under the Jenkins installation
path (set at Step 4 in Jenkins Installation).
For default installation location to C:\Program Files (x86)\Jenkins, a file
called initialAdminPassword can be found under C:\Program Files (x86)\Jenkins\secrets.
However, If a custom path for Jenkins installation was selected, then you should check that
location for initialAdminPassword file.

Step 3) Open the highlighted file and copy the content of the initialAdminPassword file.

Step 4) Paste the password it into browser’s pop-up tab


(http://localhost:8080/login?form=%2F) and click on Continue button.
Customize Jenkins
You can also customize your Jenkins environment by below-given steps:
Step 1) Click on the “Install suggested plugins button” so Jenkins will retrieve and install the
essential plugins

Jenkins will start to download and install all the necessary plugins needed to create new
Jenkins Jobs.
Note: You can choose the Option “Select Plugins to Install” and select the plugins you want
to install

Step 2) After all suggested plugins were installed, the “Create First Admin User” panel will
show up. Fill all the fields with desired account details and hit the “Save and Finish”
button.

Step 3) Once you have filled the above data, finally it will ask for URL information where
you can configure the default instance path for Jenkins. Leave it as it is to avoid any
confusions later. However, if another application is already using 8080 port, you can
use another port for Jenkins and finally save the settings, and you are done with
installation of Jenkins. Hit the “Save and Continue” button:
Congratulations! We have successfully installed a new Jenkins Server. Hit the “Start using
Jenkins” button.

Below you can find the Jenkins instance up and run, ready to create first Jenkins jobs:

RESULT:

Thus, we install the Jenkins in the windows successfully


EX.NO:3 HOW TO CREATE A NEW JOB IN JENKINS

DATE:

AIM:

To automate tasks like building, testing, and deploying software projects, create a new
job in Jenkins manually.

THEORY:

What Is a Build Job?

A Jenkins build job contains the configuration for automating a specific task or step in the
application building process. These tasks include gathering dependencies, compiling,
archiving, or transforming code, and testing and deploying code in different environments.

Jenkins supports several types of build jobs, such as freestyle projects, pipelines, multi-
configuration projects, folders, multibranch pipelines, and organization folders

What is a Jenkins Freestyle Project?

Jenkins freestyle projects allow users to automate simple jobs, such as running tests, creating
and packaging applications, producing reports, or executing commands. Freestyle projects are
repeatable and contain both build steps and post-build actions.

Even though freestyle jobs are highly flexible, they support a limited number of general build
and post-build actions. Any specialized or non-typical action a user wants to add to a freestyle
project requires additional plugins.
PROCEDURE:

How to Set up a Build Job in Jenkins

Follow the steps outlined below to set up and run a new Jenkins freestyle project.

Step 1: Create a New Freestyle Project

1. Click the New Item link on the left-hand side of the Jenkins dashboard.

2. Enter the new project's name in the Enter an item name field and select the Freestyle
project type. Click OK to continue.

3. Under the General tab, add a project description in the Description field.
Step 2: Add a Build Step

1. Scroll down to the Build section.

2. Open the Add build step drop-down menu and select Execute Windows batch
command.

3. Enter the commands you want to execute in the Command field. For this tutorial, we are
using a simple set of commands that display the current version of Java and Jenkins working
directory:

java -version
dir

4. Click the Save button to save changes to the project.


Note: Need a cheap sandboxing environment with automated OS-deployment options? See
how easy it is to deploy a development sandbox for as little as $0.10/hour.

Step 3: Build the Project

1. Click the Build Now link on the left-hand side of the new project page.

2. Click the link to the latest project build in the Build History section.

3. Click the Console Output link on the left-hand side to display the output for the
commands you entered.
4. The console output indicates that Jenkins is successfully executing the commands,
displaying the current version of Java and Jenkins working directory.

RESULT:

Thus, we create a new job in the Jenkins successfully.


EX.NO:4 HOW TO INTEGRATE JENKINS IN GITHUB

DATE:

AIM:

To integrate Jenkins in the GitHub.

THEORY:

Jenkins is an open-source automation tool that helps in the building, testing, deploying,
integration, and delivery of a software product. Using Git Plugin, any source could be easily
fetched from the Git repository that is accessible via the Jenkins build node.

Git is an open-source version control system and one of the most popular tools used by
developers to manage their codes. DevOps engineers with knowledge and experience in
handling Jenkins are in high demand.

PROCEDURE:

Step 1: Create a Jenkins Job

Let’s start by creating a new Jenkins job. Click on the “New Item”, give it a name, pick the
“Pipeline” option and click on the OK.

Step 2: Configure GitHub Hook Trigger


On the configuration page, scroll down until the section “Build Triggers” and select the
option “GitHub hook trigger for GITScm polling”
Note: We are going to setup this pipeline to trigger whenever a new commits happens on
Github repository.
Step 3: Create a GitHub Repository

Step 4: Connect a GitHub Repository


Scroll down to the “Pipeline” section. We will configure Jenkins to use GitHub repository as
source. Select “Pipeline Script from SCM” under the definition option.
From SCM dropdown, select “git”.
In the repository URL section, paste the GitHub repository URL which you want to use for this
pipeline. In my case, I am using the repository which I have created in the previous step.

Type the Jenkins file path and click on save.


Step 5: Adding a WebHook in GitHub
Login to GitHub and go to the repository which you have connected in the previous step.

Click on “WebHooks” and then click on “Add WebHooks”.

In this page, we will configure Jenkins URL so that GitHub will call Jenkins for the actions. In
the “Payload URL” section, enter Jenkins server URL which is accessible over the public
internet.
In the content type dropdown, select the option “application/json”. Leave the remaining fields
as it it click on Add Webhook. You will see a message stating that the Webhook has been
created.

Step 6: Manually Building Jenkins Job

Now go back to the Jenkins dashboard and click on the Job which we have created and then
click on “Build Now” from the left.

Step 7: Trigger Build with GitHub Commit


Go to your GitHub repository and add a new commit by making any changes and within few
seconds, you can see the build is running on the Jenkins dashboard.

RESULT:

Thus, we integrate the Jenkins with GitHub successfully.


EX.NO:5 HOW TO DO JENKINS MAVEN CONFIGURATION

DATE:

AIM:

To do the Jenkins maven configuration.

THEORY:

What is Maven?

Maven is a powerful build management tool for Java projects to help execute a build life cycle
framework. The basis of the Maven is the concept of POM (Project Object Model) in which all
configurations can be done with the help of a pom.xml file. It is a file that includes all the project and
configuration-related information such as source directory, dependencies with its version, plugins, and
builds information, test source directory, etc. A few of the key features of Maven are:
 Maven describes how the project is built. It builds a project using the Page Object Model.
 Maven automatically downloads, update as well as validate the compatibility between
dependencies.
 In Maven, dependencies are retrieved from the dependency repository, whereas plugins are
retrieved from plugin repositories, so mavens keep proper isolation between project
dependencies and plugins.
 Maven can also generate documentation from the source code, compiling and then packaging
compiled code into JAR files or ZIP files.
What is Maven Plugin for Jenkins?
The Maven Plugin is a plugin that provides the capabilities to configure, build, and run Maven-
based projects in Jenkins. This is a must pre-requisite for the integration of Maven with
Jenkins. Let's see how to can install Maven's integration plugin in Jenkins:
PROCEDURE:

How to install Maven Plugin in Jenkins?


Follow the steps as mentioned below to install the Maven plugin in Jenkins:
1st Step: Click on the Manage Jenkins link in the left menu bar, as highlighted below:

2nd Step: Under the System Configuration section, click on the Manage Plugins options:
Manage Plugins Section in Jenkins

3rd Step: Under the Plugin Manager, click on the Available tab (marker 1) and search for the
maven plugin (marker 2). It will show the Maven Integration plugin as a result (marker 3):

4th Step: Select the checkbox in front of the Maven Integration plugin and click on the Install
without restart button:
5th Step: Once the plugin installs successfully, click the checkbox to restart Jenkins:
restart jenkins after maven plugin installation

6th Step: After the restart of Jenkins, the Maven Jenkins plugin will be installed successfully
and ready for configuration.
After the installation of the Maven Jenkins plugin, let's see how we can configure and integrate
the Maven with Jenkins:
How to integrate Maven with Jenkins?

The reason behind integrating Maven with Jenkins is so that we can execute Maven commands
through Jenkins as we will majorly use Maven for Java projects. Hence, JDK also comes as a
pre-requisite for this setup. So, let's fir quickly see how to can specify the java path in Jenkins:

How to setup Java Path in Jenkins?

Maven integration with Jenkins starts with setting up the Java path in Jenkins. Kindly follow
the below steps to setup Java path in Jenkins:

Step 1: Open the Jenkins and go to Jenkins Dashboard. After that, click on the Manage Jenkins
link as shown below:
As soon as we click on the "Manage Jenkins" link, we will redirect towards the Manage Jenkins
page in which we can see different types of options, and from here, we can see the "Global
Tool Configuration" option.
Step 2: Now click on the Global Tool Configuration link as highlighted below:

As soon as we click on Global Tool Configuration, we will be redirected to the Global tool
configuration page to specify different configurations.
Step 3: After that, we need to set the JDK path in Jenkins. To set the JDK path in Jenkins,
please follow the below-highlighted steps:
 Click on the Add JDK button. Kindly note that by default, "Install Automatically" will be
checked, so since we are going to use the JDK installed in our local machine, "Install
automatically" will install the latest version of JDK, and you will also need to provide
credentials to download relevant JDK.
 Give JDK's name as we gave as JDK 1.8, as this is currently installed in my machine.
 Give the path of JDK in JAVA_HOME textbox.
After this, the JDK path is properly set up in Jenkins. Now, the next task is to set up the Maven
path in Jenkins.
How to setup Maven Path in Jenkins?
In the previous section, we saw how to set up the Java path in Jenkins, and now, in this section,
we will set up the Maven path in Jenkins. Please follow the below steps to set up the Maven
path in Jenkins.

1. Click on the Add Maven button. Kindly note that by default, "Install Automatically"
will be checked, so we will uncheck it because we don't want that Jenkins will
automatically install the latest version of Maven.
2. Give the name of Maven as we gave as Maven 3.6, as this is the version set up in my
machine.
3. Give the path of Maven in the MAVEN_HOME textbox.
4. Click on the Save button.
Now that we have configured both Java and Maven in Jenkins, Let's see how to create and
execute a Maven project in Jenkins?
What is a Maven project in Jenkins?
Jenkins provides a particular job type, which explicitly provides options for configuring and
executing a Maven project. This job type is called the "Maven project." Let's see how we can
create a Maven project in Jenkins and run the same.
How to create a Maven project in Jenkins?
We know that the pom.xml file is the heart of Maven projects. For demonstration purposes, we
already created a maven project, which is pushed into the GitHub repository. Kindly visit the
link Understanding GitHub to understand more about Git and GitHub. For creating a Maven
project in Jenkins, follow the steps as mentioned below:
Step 1: Firstly, we need to create a job. To create this, click on the "New Item" option as
highlighted below:

2nd Step: Now, do the following steps to create a new maven project:

1. Give the Name of the project.


2. Click on the Maven project. Kindly note that If this Maven Project option is not visible,
we need to check whether the "Maven Integration" plugin is installed in Jenkins. If not
installed, then install it and restart Jenkins. For more details, please refer to our article
“Install Jenkins".
3. Click on the OK button.
3rd Step: Describe the project in the description section.

Now, go to the further sections like Source Code Management and Build Triggers section.

4th Step: Select the Git option in "Source Code Management " as per our requirement because
we will pull our Maven project from the GitHub repository.
Also, if we need to select the "GitHub hook trigger for GITScm polling" option in the "Build
Triggers" section, we will trigger our build with the help of webhooks.

5th Step: Now perform the following highlighted steps to move further:

1. Firstly, give the relative path of pom.xml in the Root POM textbox, as we do have the
pom.xml at the root of the project, so we directly provided the file's name.
2. Secondly, type "clean install" in the Goals and options textbox as "maven clean,"
"maven install," as well, as "maven test" are the maven commands while running
maven build but here "clean install" command is sufficient to trigger build from Jenkins.
3. Finally, click on the Save button.
So, our Maven project setup finishes and is ready to run. In the further subsection, we will see
how to execute a Maven project in Jenkins.
How to execute a Maven project in Jenkins?
As our maven project is already setup in the previous section, we are now ready to execute it.
After setup, a Maven project is similar to other job types in Jenkins. Jenkins provides multiple
ways to execute jobs. Apart from the manual execution, a few of the options to automatically
executing the jobs are highlighted below:
You can select one or all of the above-mentioned options to trigger the build automatically.
Let's understand under what all conditions these options will trigger the build:

RESULT:
Thus, we do Jenkins maven configuration successfully.

You might also like