Day 24 & 25 Complete Jenkins CI/CD Project

Day 24 & 25 Complete Jenkins CI/CD Project

Β·

3 min read

Day 24 & 25 of #90daysofdevops

Hey Techies! Welcome to this blog

In this blog, we are going to start Jenkins CI/CD Project.

Introduction

If you've been following along, you're already familiar with the basics of Jenkins and how it can be used for Continuous Integration and Continuous Deployment.

Prerequisites

Before we begin, ensure the following prerequisites are met:

  • Your ec2 instance is up and running.

  • Jenkins is installed and running.

  • Docker and Docker Compose are installed on your server.

Task-01

Follow this repo GitHub Repo .

Fork this repository:

First things first, fork the project repository on GitHub. This will create a copy of the original repository in your GitHub account, allowing you to make changes without affecting the original project.

Create a connection to your Jenkins job and your GitHub Repository via GitHub Integration:

For a successful CI/CD setup, it's crucial to connect Jenkins with your GitHub repository. Jenkins can monitor your repository for changes and trigger builds when new commits are pushed.

Configure Credentials

  1. Generate SSH Keys: On your EC2 instance, run ssh-keygen to generate SSH keys. Use the generated public key for GitHub

To create a Public key we have to use cat /home/ubuntu/.ssh/id_rsa.pub

To configure the GitHub Goto account setting < SHH and GPG keys and paste the ssh-rsa key here.

Add SSH Key to GitHub: In GitHub settings, add a new SSH key with the generated public key.

Read About GitHub WebHooks and make sure you have CI/CD setup:

To install GitHub integration plugins go to the Jenkins dashboard > Manage Jenkins > Plugins

Jenkins Credentials: In Jenkins credentials section, select "SSH username with private key" in the "Kind" field. Use "github-jenkins" as the ID and "ubuntu" as the username. Enter the private key directly.

Set Up Build Triggers

  1. Enable GitHub Hook Trigger: In the "Build Triggers" section, check "GitHub hook trigger for GITScm polling." This ensures that Jenkins is triggered upon code changes in your GitHub repository.

  2. Define Build Steps

    Add Execute Shell Build Step: In the "Build" section, add an "Execute shell" build step. Enter the command docker-compose down && docker-compose build --no-cache && docker-compose up -d --build to handle Docker Compose actions.

    Save the Jenkins Job

    Click "Save" to store your Jenkins job configuration.

GitHub Webhook Configuration

GitHub Webhook Setup

  1. Navigate to GitHub Settings: In your GitHub repository, click on "Settings" and select "Webhooks."

  2. Add Webhook: Click "Add webhook" to set up a new webhook.

Configure Webhook

  1. Enter Payload URL: In the "Payload URL" field, enter <ipaddress:8080/github-webhook/>. Ensure to replace <ipaddress> with the actual IP of your Jenkins server.

  2. Set Content Type: Choose "application/json" as the content type.

  3. Save Webhook: Click "Add webhook" to save your webhook configuration.

Test the Jenkins Job

  1. Build Now: Go to your Jenkins job and click "Build Now" to test if the setup is correct.

  1. Check Console Output: Monitor the build console output for any errors or issues.

Test the Deployment

  1. Open Browser: In your web browser, navigate to <ipaddress:8000> to verify that your app is successfully deployed.

    Verify Webhook

    1. Make Changes in GitHub: Make changes to your GitHub repository to test the webhook.

    2. Check Jenkins: Observe Jenkins for triggered builds and successful deployments.

That's it! You've just created your first Jenkins CI/CD Project. πŸŽ‰

Thank you so much for taking the time to read till the end! Hope you found this blog informative and helpful.

Feel free to explore more of my content, and don't hesitate to reach out if need any assistance from me or in case of you have any questions.

Happy Learning!

~kritika :)

Connect with me: linkedin.com/in/kritikashaw

Β