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?
Source Code Management Integration: Jenkins pulls the latest code from version control systems (e.g., GitHub, Bitbucket).
Build Automation: It compiles the code and packages it into an executable format.
Testing: Jenkins runs automated tests to ensure the code is stable and bug-free.
Deployment: It deploys the code to the production environment or a staging server.
Monitoring and Notifications: Jenkins provides real-time feedback and notifications to the development team about the build status.
Benefits of Using Jenkins:
Improved Code Quality: Automated testing helps catch bugs early in the development process.
Faster Delivery: Continuous integration and delivery speeds up the release cycle.
Increased Productivity: Automation frees up developers to focus on writing code rather than manual tasks.
Collaboration: Jenkins facilitates better collaboration between development and operations teams.
Getting Started with Jenkins:
Installation: Jenkins can be installed on various operating systems including Windows, macOS, and Linux.
Configuration: Set up your Jenkins server, configure the necessary plugins, and connect it to your version control system.
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 )
New Item :
Enter Item Name (Job Name )
Select Free Style Project & Click OK
Enter Some Description
Go to "Source Code Management " Tab and Select "Git"
Enter Project "Git Repo URL "
Add Your Git-hub Account Credentials
Go to "Build Tab "
Click On Add "Build" Step And Select " Invoke Top Level Maven Targets "
Select Maven and Enter Goals "clean package"
Click On "Post Build Action " and Select "Deploy War /Ear to Container" Option
Give path of war file (you can give like this also : **/*. war )
Enter Context Path (Give your Project Name )
Click On "Add Container" and Select Tomcat Version 9.x
Add Tomcat Server Credentials (Give Username and password which is having manager-script role )
Enter Tomcat Server URL (EC2-VM-IP :Tomcat server Port)
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