Task 1: Understanding Jenkins
What is Jenkins?
Jenkins is like the superhero of the tech world, helping developers automate their work and make life easier. It's an open-source tool written in Java, designed for continuous integration and delivery (CI/CD). Now, don't let the fancy terms scare you; think of it as your personal assistant in the coding universe.
How Does Jenkins Work?
Imagine having a robot that can build, test, and deploy your software without you lifting a finger. That's Jenkins! It runs on Java and uses something called pipelines to manage the whole process. These pipelines are like highways, guiding your code from one stage to another seamlessly.
Why Do We Need Jenkins?
Humans can be a bit lazy, right? Jenkins comes to the rescue by taking care of repetitive tasks. It's like having a friend who handles the boring stuff, so you can focus on the fun and creative parts of coding.
Task 2: Creating a Freestyle Pipeline
Let's dive in and set up a straightforward pipeline in Jenkins that prints "Hello World!!"
Step 1: How to Install Jenkins?
- First of all, we need to install Java using the following commands:
sudo apt update
sudo apt install fontconfig openjdk-17-jre
java -version
- Now, install Jenkins using the commands below:
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
Step2: Start Jenkins
- Enable the Jenkins service to start at boot:
sudo systemctl enable jenkins
- Start the Jenkins service:
sudo systemctl start jenkins
- Check the status of the Jenkins service:
sudo systemctl status jenkins
Step3: To run Jenkins, open port 8080 in the security group of your instance:
Navigate to the instance and click on the security group.
Add a security rule for port 8080 and save the rule.
- After adding the security rule for port 8080, proceed with the following steps to get started with Jenkins:
- Create your first admin user.
- Jenkins is now ready for use!
Step 4: Open Jenkins
- Make sure Jenkins is installed on your machine. If not, follow the Installation Guide.
Step 5: Create a New Item
Click on "New Item" on the Jenkins dashboard.
Give your project a name, like "HelloWorldPipeline."
Step 6: Choose Freestyle Project
Select "Freestyle project" and click "OK."
Step 7: Configure the Pipeline
Scroll down to the "Build" section and click on "Add build step."
Choose "Execute shell" from the dropdown.
Step 8: Write Shell Command
In the command box, type
echo "Hello World!!"
Step 9: Save and Run
Save your project configuration.
Click on "Build Now" to run your pipeline.
Step 10: Check Console Output
- After the build, click on the build number, then "Console Output" to see the magic happen.
Congratulations! You've just created a simple Jenkins pipeline. Share your success on LinkedIn and let the world know about your coding prowess!
Happy Coding!