Jenkins
ekanadh

Jenkins

Jenkins

Introduction to Jenkins

Jenkins is a popular open-source automation tool used for Continuous Integration (CI) and Continuous Deployment (CD) in software development.

It helps developers automate code building, testing, and deployment, making the software development process faster and error-free.

?? CI (Continuous Integration): Developers frequently merge code changes into a shared repository, and Jenkins automatically tests the code to catch errors early.

?? CD (Continuous Deployment): Jenkins can automatically deploy tested code to production or staging environments.

Why Use Jenkins?

? Automates the software development process – No need for manual builds and deployments.

? Detects bugs early – Runs tests automatically after every code change.

? Saves time – Eliminates repetitive tasks with automation.

? Integrates with tools like Git, Docker, Kubernetes, AWS, Maven, and more.

? Free & Open Source – No licensing cost.

Step 1: Install Jenkins

For Windows:

1?? Download Jenkins from [https://www.jenkins.io/download/](https://www.jenkins.io/download/)

2?? Install Java 11 or Java 17 (Required for Jenkins).

3?? Run the Jenkins .war file:

java -jar jenkins.war --httpPort=8080

4?? Open https://localhost:8080 in your browser.

For Linux (Ubuntu/Debian):

1?? Update your system:

sudo apt update && sudo apt upgrade -y

2?? Install Java:

sudo apt install openjdk-11-jdk -y

3?? Add Jenkins repository and install:

curl -fsSL https://pkg.jenkins.io/debian/jenkins.io.key | sudo tee \

/usr/share/keyrings/jenkins-keyring.asc > /dev/null

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 update

sudo apt install jenkins -y

4?? Start and enable Jenkins:

sudo systemctl start jenkins

sudo systemctl enable jenkins

5?? Open Jenkins in your browser:

- Go to https://localhost:8080

- Use the admin password from /var/lib/jenkins/secrets/initialAdminPassword

Step 2: Configure Jenkins

1?? Unlock Jenkins

- When you open https://localhost:8080, it will ask for a password.

- Find it using:

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

- Paste the password and continue.

2?? Install Recommended Plugins

- Click "Install suggested plugins" (Jenkins will install Git, Maven, and other essential plugins).

3?? Create an Admin User

- Enter username, password, and email.

4?? Setup Jenkins URL

- Use https://localhost:8080 or your server IP.

Now, Jenkins is ready! ??

Step 3: Create Your First Jenkins Job (Freestyle Project)

1?? Go to Jenkins Dashboard → Click "New Item"

2?? Enter a Job Name (e.g., MyFirstJenkinsJob)

3?? Select "Freestyle Project" → Click OK

4?? Under Build Steps, click "Add build step" → Choose "Execute Shell"

5?? Add a simple script:

echo "Hello, Jenkins!

6?? Click "Save" → Click "Build Now"

7?? Go to "Console Output", and you will see:

Hello, Jenkins!

Build Successful

Step 4: Automate Code Build using Git & Maven

Let’s create a CI pipeline that automatically fetches code from GitHub, builds using Maven, and runs tests.

1. Install Git & Maven in Jenkins

- Go to Manage JenkinsGlobal Tool Configuration

- Under Git, click Install Automatically

- Under Maven, add a new Maven installation and select a version.

2. Create a New Jenkins Job for Maven Build

1?? Go to "New Item"Enter a job name → Select "Freestyle Project"

2?? Under Source Code Management, select Git

- Enter your GitHub Repository URL

- If private, add credentials.

3?? Under Build Triggers, select Poll SCM

- Add H/5 (checks for updates every 5 minutes).

4?? Under Build Steps, select "Invoke top-level Maven targets"

- Add Goals: clean install

5?? Click "Save" and "Build Now"

?? Now, Jenkins will automatically fetch code, build, and run tests whenever there’s a new commit in GitHub!

---

Step 5: Automate Deployment using Jenkins & Docker

Let’s automate the deployment of a Spring Boot application inside a Docker container.

1. Install Docker on Jenkins Server


sudo apt install docker.io -y

sudo usermod -aG docker jenkins


Restart Jenkins:


sudo systemctl restart jenkins


2. Create a New Job for Docker Deployment

1?? Create a Freestyle Project

2?? Under Source Code Management, select Git

- Enter your GitHub Repo URL

3?? Under Build Steps, click "Add build step" → Choose "Execute Shell"

4?? Add a script to build & run the Docker container:

docker build -t myapp:latest .

docker run -d -p 8080:8080 myapp


5?? Click "Save" and "Build Now"

?? Jenkins will now automatically pull the latest code, build a Docker image, and deploy it!


Step 6: Jenkins Pipeline (Advanced CI/CD Automation)

Jenkins Pipeline allows you to define the entire CI/CD process as code.

1. Create a Jenkinsfile in Your GitHub Repo

```groovy

pipeline {

agent any

stages {

stage('Checkout Code') {

steps {

git 'https://github.com/user/repo.git'

}

}

stage('Build') {

steps {

sh 'mvn clean package'

}

}

stage('Docker Build & Push') {

steps {

sh '''

docker build -t myapp:latest .

docker tag myapp:latest myrepo/myapp:latest

docker push myrepo/myapp:latest

'''

}

}

stage('Deploy') {

steps {

sh 'docker run -d -p 8080:8080 myrepo/myapp:latest'

}

}

}

}

### 2. Create a Pipeline Job in Jenkins

1?? Click "New Item" → Select "Pipeline"

2?? Under Pipeline Definition, choose "Pipeline script from SCM"

3?? Select Git → Add your Repo URL

4?? Click Save and Build Now

?? Now, Jenkins will automatically build, push, and deploy every time new code is committed!

## Conclusion

? Jenkins automates CI/CD, making software delivery faster and more efficient.

? You can integrate Jenkins with Git, Docker, Kubernetes, AWS, and more.

? Using Jenkins Pipelines, you can write CI/CD as code for full automation.

?? Next Steps: Learn Jenkins with Kubernetes for advanced deployments!

Do you use Jenkins in your projects? Let’s discuss! ??

#Jenkins #CICD #Automation #DevOps #FullStackDevelopment #100DaysOfCode ??

要查看或添加评论,请登录

Ekanadh Reddy的更多文章

  • Dependency Injection in Spring Boot

    Dependency Injection in Spring Boot

    Dependency Injection in Spring Boot: Mastering Dependency Injection in Spring Boot: A Key to Cleaner Code If you’ve…

    1 条评论
  • Pagination in REST APIs – Don’t Overload Your Frontend!

    Pagination in REST APIs – Don’t Overload Your Frontend!

    #Day13 of #100DaysOfFullStack Today's Topic: Pagination in REST APIs – Don’t Overload Your Frontend! Imagine requesting…

  • Spring WebFlux vs Spring MVC

    Spring WebFlux vs Spring MVC

    Spring WebFlux vs Spring MVC: Understanding Reactive Programming in Java Introduction In modern web applications…

  • Introduction to Exceptions in Java

    Introduction to Exceptions in Java

    Exception Handling in Java – A Complete Guide Introduction to Exceptions in Java In Java, an exception is an event that…

  • HashMap in Java

    HashMap in Java

    HashMap in Java – A Complete Guide with Real-Time Examples Introduction to HashMap A HashMap in Java is a widely used…

  • ArrayList in Java – A Complete Guide

    ArrayList in Java – A Complete Guide

    Introduction to ArrayList In Java, an ArrayList is a resizable array that provides a dynamic way to store and manage…

  • Spring Boot vs Node.js – Which One to Choose for Backend Development?

    Spring Boot vs Node.js – Which One to Choose for Backend Development?

    Day 3: Spring Boot vs Node.js – Which One to Choose for Backend Development? ?? ?? Introduction When it comes to…

  • PostgreSQL

    PostgreSQL

    #Day2: Understanding PostgreSQL - The Advanced Open-Source Database What is PostgreSQL? PostgreSQL (often called…

  • Understanding Threads in Java

    Understanding Threads in Java

    Understanding Threads in Java: (Step by Step) Imagine you are in a restaurant kitchen where multiple chefs are working…

  • Why Hibernate is a Better Choice than JDBC for Java Applications.

    Why Hibernate is a Better Choice than JDBC for Java Applications.

    Why Hibernate is a Better Choice than JDBC for Java Applications When building Java applications, interacting with…

    2 条评论

社区洞察

其他会员也浏览了