Skip to main content

Command Palette

Search for a command to run...

Day 25 Task: 🚀Complete Jenkins CI/CD Project - Continued with Documentation 📄

Published
•4 min read
Day 25 Task: 🚀Complete Jenkins CI/CD Project - Continued with Documentation 📄
A

"I'm a 3rd-year Computer Engineering student at Marwadi University with skills in C++, web development (MERN stack), and DevOps tools like Kubernetes. I contribute to open-source projects and share tech knowledge on GitHub and LinkedIn. I'm learning cloud technologies and app deployment. As an Internshala Student Partner, I help others find jobs and courses." now currently focusing on #90DaysOfDevops

Introduction

We completed till day 24 , we deployed project through cicd pipeline and learn aboout github hooks and many things so in this blog i made documentation about what we learned in jenkins

Steps for Jenkins CI/CD Project

Let's dive into the detailed documentation.

GitHub Setup

  1. Create a GitHub Account: If you don't already have a GitHub account, you can create one by following the steps in Creating an account on GitHub.

  2. Create a GitHub Repository: Once your account is set up, create a new repository by following the instructions in Create a GitHub Repository.

  3. Set Up Git Configuration:

    • Open your terminal or command prompt.

    • Configure your Git username and email:

        git config --global user.name "Your Name"
        git config --global user.email "your-email@example.com"
      
  4. Clone the Repository:

    • Copy the repository URL from GitHub.

    • Clone the repository to your local machine:

        git clone https://github.com/your-username/your-repository.git
      
  5. Initialize Git Repository:

    • Navigate to your project directory:

        cd your-repository
      
    • Initialize the Git repository:

        git init
      
  6. Add Files:

    • Add your project files to the repository:

        git add .
      
  7. Commit Changes:

    • Commit your changes with a message:

        git commit -m "Initial commit"
      
  8. Push Changes:

    • Push your changes to the remote repository:

        git push origin main
      

Docker and jenkins installation in ubuntu

  1. Install Docker:

    • Update your package list:

        sudo apt-get update
      
    • Install Docker:

        sudo apt-get install -y docker.io
      
  2. Install Docker Compose:

    • Download the Docker Compose binary:

        sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
      
    • Apply executable permissions:

        sudo chmod +x /usr/local/bin/docker-compose
      
  3. Install Java:

    • Install Java Development Kit (JDK):

        sudo apt-get install -y openjdk-11-jdk
      
  4. Add Jenkins Repository Key:

    • Add the Jenkins repository key:

        wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add -
      
  5. Add Jenkins Repository:

    • Add the Jenkins repository to your sources list:

        sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
      
  6. Install Jenkins:

    • Update your package list and install Jenkins:

        sudo apt-get update
        sudo apt-get install -y jenkins
      
  7. If you phase any problem then follow this link jenkins installation

  8. Jenkins Service:

    • Start the Jenkins service:

        sudo systemctl start jenkins
      

Docker Setup

  1. Add User to Docker Group:

    • Add your user to the Docker group:

        sudo usermod -aG docker $USER
      
  2. Verify User Group Addition:

    • Verify that your user has been added to the Docker group:

        groups $USER
      
  3. Fix Docker Permission Errors:

    • If you encounter permission errors, restart your machine or log out and log back in.
  4. Create a Dockerfile:

    • Create a Dockerfile in your project directory. Example:

        FROM openjdk:11
        COPY . /app
        WORKDIR /app
        RUN ./mvnw package
        CMD ["java", "-jar", "target/your-app.jar"]
      
  5. Build Docker Image:

    • Build your Docker image:

        docker build -t your-app .
      
  6. List Docker Images:

    • List your Docker images to verify the build:

        docker images
      
  7. Run Docker Container:

    • Run your Docker container:

        docker run -p 8080:8080 your-app
      
  8. List Running Containers:

    • List running containers to verify your application is running:

        docker ps
      
  9. Set Up Inbound Rules: Add specific ports to your instance for accessing your application via browser (refer to Setting up inbound rules).

Jenkins Setup

  1. Access Jenkins: Visit <Your_Public_IP:8080> in your browser.

  2. Unlock Jenkins: Use the admin password found in the location specified in the Jenkins setup page.

  3. Set Up Jenkins: Follow the instructions in the Jenkins setup wizard to complete the setup.

  4. Create a Freestyle Job: Create your first Jenkins job by referring to the Jenkins documentation on First Freestyle Job.

GitHub Webhook Integration

  1. Create a Webhook in GitHub: Set up a webhook in your GitHub repository by following the instructions in How to create a Webhook.

  2. Configure Webhook:

    • Payload URL: <Jenkins_URL:port/github-webhook/>

    • Select Events: Choose the events that should trigger the webhook.

  3. Add Webhook: Click on the “Add webhook” button and refresh the page to confirm activation.

  4. Integrate Webhook with Jenkins Job: Follow the steps in the Jenkins documentation to integrate the webhook with your Jenkins job.

  5. Test Integration: Make changes to any file in your GitHub repo, commit the changes, and verify that Jenkins triggers the job automatically.

  6. Access Application: Use <Your_Public_IP>:Port specified in your application to verify deployment.

Thankyou for reading !!!!!

90DaysOfDevops

Part 21 of 49

So In This Series I am following 90 DaysOfDevops challenge , what i will learn in my devops journey i will share with you with my blogs ,You will get blog on tools which used by devops engineer , example :- Linux,ansible,terraform,docker,etc

Up next

Day 24: 🚀Mastering Webhooks for Jenkins and GitHub Integration 🔗

What is Web hooks ? Webhooks are a way for one system to send real-time data to another system when a specific event happens. In the context of Jenkins and GitHub, webhooks are used to automatically trigger Jenkins jobs when changes are made in a Git...

More from this blog

A

Anand Raval

118 posts

Hello I am Anand Raval , i contributed my work in robotics(arduino uno) , fronted web devloper,competitive programming, now currently focusing on #90DaysOfDevops