Mastering Jenkins: A Full Guide

Mastering Jenkins: A Full Guide

Complete Jenkins Guide for Beginners

ยท

6 min read

Jenkins: An Overview ๐ŸŒŸ

What is Jenkins?

Jenkins is an open-source automation server that enables developers to build, test, and deploy their software. Itโ€™s a cornerstone tool in the field of continuous integration (CI) and continuous delivery (CD).

How Does Jenkins Work?

  1. Source Code Management Integration: Jenkins pulls the latest code from version control systems (e.g., GitHub, Bitbucket).

  2. Build Automation: It compiles the code and packages it into an executable format.

  3. Testing: Jenkins runs automated tests to ensure the code is stable and bug-free.

  4. Deployment: It deploys the code to the production environment or a staging server.

  5. Monitoring and Notifications: Jenkins provides real-time feedback and notifications to the development team about the build status.

Benefits of Using Jenkins:

  1. Improved Code Quality: Automated testing helps catch bugs early in the development process.

  2. Faster Delivery: Continuous integration and delivery speeds up the release cycle.

  3. Increased Productivity: Automation frees up developers to focus on writing code rather than manual tasks.

  4. Collaboration: Jenkins facilitates better collaboration between development and operations teams.

Getting Started with Jenkins:

  1. Installation: Jenkins can be installed on various operating systems including Windows, macOS, and Linux.

  2. Configuration: Set up your Jenkins server, configure the necessary plugins, and connect it to your version control system.

  3. Creating Pipelines: Define your build, test, and deployment pipelines using Jenkins-file, a text file that contains the pipeline definition.

here is useful commands for install Jenkins

Prerequisites for Using Jenkins ๐ŸŒŸ

  • A machine with at least 256 MB of RAM (recommended: 1 GB or.......

  • Java installed on your machine

commands for installation Jenkins on ubuntu Linux machine

sudo wget -O /usr/share/keyrings/jenkins-keyring.asc \
  https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key
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

for start Jenkins use following commands

sudo systemctl enable jenkins
sudo systemctl start jenkins
sudo systemctl status jenkins

Open your EC2 instance public IP (https://<public_IP>:8080/) along with port 8080 in your favorite browser. And provide the administration password obtained during the installation.

Note: Make sure you enable 8080 port in Security Group Inbound Rules.

Get the initial administration password

$sudo cat /var/lib/jenkins/secrets/initialAdminPassword

Now your Jenkins started : Create Admin user

๐ŸŽ‰๐ŸŽ‰Now , appreciate yourself you successfully deploy Jenkins on your machine ๐ŸŽ‰๐ŸŽ‰

its is Look like this : Jenkins up and Running


Now moving towards advance concepts ---->>>>>>>

Now we want to create job in Jenkins

Steps for create job in Jenkins

Jenkins Job with GIT HUB Repo + Maven + Tomcat server Integration and Deployment

Pre-Requisites : Java , Git , and Maven

Git installation :

$sudo apt install git -y

JDK Installation :

In your Jenkins Dashboard -> Manage Jenkins -> Global tools configuration -> Add JDK -> Choose JDK 8 -> Configuration Oracle Account Credentials

Maven Installation :

Jenkins Dashboard -> Manage Jenkins -> Global tools Configuration -> Add Maven

Plugin Installation :

Jenkins Dashboard -> Manage Jenkins -> Manage Plugins -> Goto Available -> Search for "Deploy Container" Plugin -> Install it .

what we done so far ??? ---->> install git in our machine and in Jenkins we install maven , JDK , and plugins ....we all set for creating Jenkins Job

Sample Git Repo URLS For Practice

Git Hub Repo URL : https://github.com/divyasatpute/maven-jenkins-app-.git

Now go to your tomcat server and configure below users in " tomcat-users .xml" file (it will be available in tomcat server conf folder )

<role rolename="manager-gui" />
<user username="tomcat" password="tomcat" roles="manager-gui" />
<role rolename="divya-gui" />
<role rolename="manager-script"/> 
<user username="divya" password="divya" roles="manager-gui,divya-gui, manager-script"/>

Now create Jenkins job (step for create )

  1. New Item :

  2. Enter Item Name (Job Name )

  3. Select Free Style Project & Click OK

  4. Enter Some Description

  5. Go to "Source Code Management " Tab and Select "Git"

  6. Enter Project "Git Repo URL "

  7. Add Your Git-hub Account Credentials

  8. Go to "Build Tab "

  9. Click On Add "Build" Step And Select " Invoke Top Level Maven Targets "

  10. Select Maven and Enter Goals "clean package"

  11. Click On "Post Build Action " and Select "Deploy War /Ear to Container" Option

  12. Give path of war file (you can give like this also : **/*. war )

  13. Enter Context Path (Give your Project Name )

  14. Click On "Add Container" and Select Tomcat Version 9.x

  15. Add Tomcat Server Credentials (Give Username and password which is having manager-script role )

  16. Enter Tomcat Server URL (EC2-VM-IP :Tomcat server Port)

  17. Click On Apply and Save .

Heyyy buddyyy , look you able to all : Hereโ€™s a quote for you

"Congratulate yourself for the journey youโ€™ve undertaken, for the progress youโ€™ve made, and for the strength youโ€™ve shown. Every step forward is a victory worth celebrating.๐ŸŒŸ๐Ÿ‘๐ŸŽ‰"

What are Jenkins jobs?

Jobs are the heart of Jenkins's build process. A job can be considered as a particular task to achieve a required objective in Jenkins. Moreover, we can create as well as build these jobs to test our application or project. Jenkins provides the following types of build jobs, that a user can create on a need basis. Consequently, the following image highlights a few of the Jenkins build jobs, which are used very frequently these days:

**Let's understand the details of these various types of Jenkins build jobs:
**

How to create a job in Jenkins?

Step 1: Firstly, login into Jenkins account with valid credentials. After that, click on the "New Item" option in Jenkins dashboard.

As soon as, we will click, we will be redirected to a new page where we need to fill in the name of the job and select the type of job.

Step 2: Secondly, let's create a Freestyle project to build and run the project stored in the GitHub repository:

  • First, enter the item name.

  • Second, select the project type ( I selected the Freestyle project).

  • Third, click on the Ok button.

As soon as we click on the OK button, the Jenkins Job will be created.

So, in this way Job can be created in Jenkins. in the next section, we will see how to configure this newly created job.

How to configure a job in Jenkins?

In the previous section, we created a FreeStyle job in Jenkins. Let's see in this section that how to configure the above created Jenkins build job? Kindly follow the below steps:

Step 1: First, select the "Configure" option that is shown in the dropdown in the below image.

Moreover, as soon as we will click on the configure option then we will redirect towards the Configuration page.

Step 2: Secondly, set the purpose of the job in the "Description" section.

Apart from the description, there will be some options in the General section. Let's shortly see those options:

Step 3: Thirdly, in the Source Code Management section, we need to select the repository where we pushed our code.

As I pushed our code in the GitHub repository so I selected the Git option in the above image.

Step 4: Fourthly, go to the "Build triggers" section and select the appropriate option as per requirements. There are different options available here under the build triggers section.

Let's understand the details of all these options:

Step 5: Fifthly, go to the "Build" section. In this section, there are some most popular options available that are listed in the below table:

Now click save and apply

Did you find this article valuable?

Support Divya_satpute's_blog by becoming a sponsor. Any amount is appreciated!

ย