Linux, Git, Git-Hub, and Docker are finished, so let's learn the CI-CD tools to deploy them.
What is Jenkins?
Jenkins is an open-source automation server used for continuous integration and continuous delivery (CI/CD) of software projects. It was originally developed as the Hudson project in 2004, but in 2011, it was forked and renamed Jenkins.
Jenkins is a popular tool among developers and DevOps teams for automating various tasks related to building, testing, and deploying software applications. It provides a wide range of plugins that can be used to integrate with other tools and technologies used in the software development process.
Jenkins runs on a web container, such as Apache Tomcat, and can be accessed through a web interface or via a command-line interface. It is written in Java and supports a variety of operating systems, including Windows, macOS, and Linux.
Some of the key features of Jenkins include:
Continuous integration and continuous delivery (CI/CD) support
Extensibility through a wide range of plugins
Distributed build support
Easy installation and configuration
Integration with a variety of tools and technologies, such as GitHub, Docker, and Selenium
Robust security features, such as user authentication and authorization, and support for SSL encryption.
Install Jenkins on an EC2 Ubuntu instance:
Connect to your EC2 instance via SSH using your preferred terminal client.
Update your package manager by running the following command:
sudo apt update
Install Java on your EC2 instance by running the following command:
sudo apt install openjdk-11-jre java -version #verify java
Import the Jenkins GPG key to verify the integrity of Jenkins packages by running the following command:
curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key | sudo tee \ /usr/share/keyrings/jenkins-keyring.asc > /dev/null
Add the Jenkins repository to the package sources by running the following command:
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
Update your package manager again by running the following command:
sudo apt-get update
Install Jenkins by running the following command:
sudo apt-get install jenkins
Start the Jenkins service by running the following command:
sudo systemctl start jenkins
Or we can add Jenkins as a user
sudo usermod -aG jenkins $USER
By default, Jenkins runs on port 8080, so you'll need to open this port in your security group to access the Jenkins web interface.
Verify that Jenkins is running by running the following command:
sudo systemctl status jenkins
To access the Jenkins web interface, follow these steps:
Open a web browser on your local machine.
Navigate to your EC2 instance's public IP address or DNS name followed by the port number on which Jenkins is running. The default port number for Jenkins is 8080. For example, if your EC2 instance's public IP address is
52.11.22.33
, you would enterhttp://52.11.22.33:8080/
in your web browser's address bar.You should see the Jenkins login screen. If this is your first time accessing Jenkins, you will need to retrieve the initial administrative password. To do this, SSH into your EC2 instance and run the following command to retrieve the password from the Jenkins log file:
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
Copy and paste the password into the Jenkins login screen and click "Continue".
You should now be on the Jenkins home screen and can start using Jenkins.
Create a freestyle pipeline to print "Hello World!!"
Step 1: Click on a new item, and then you will have a page on which you have to give your name to your job and choose ‘freestyle project’ or any other option according to your need and then click ‘ok’.
Step 2: After this, you will reach a page where you have different options(like build, build triggers, and source code management) that help you manage your job.
Step 3: Now, we will give some description of our job.
Step 4: Now, you have to provide which source code management tool you are using since here we are not using anyone so will choose the ‘none’ option.
Step 5: After this, if you want to give some triggers then you can choose accordingly even Jenkins provides us with scheduled triggers. And you can choose to build an environment also accordingly. But, here we are making a simple job, so we are not using any triggers and build environment options.
Step 6: In the build section we have an option ‘Execute Windows batch command’ by which we can write some command or code.
Step 7: Now, you can give the command according to your need.
Then click apply and save. So, your job is created.
Step 8: Now, we will run it for which click the ‘build now’ option, and a building history will be created then click on it.
Step 9: Now, Click on console output, and you can see your output. Also, by console output, you can see whether your job is failed or successful.