Complete Jenkins CI/CD Project

Complete Jenkins CI/CD Project

Task 1

  1. Fork this repository.

  2. Set up a connection between your Jenkins job and your GitHub repository through GitHub Integration.

  3. Learn about GitHub WebHooks and ensure you have configured the CI/CD setup.

Solution:

1. Fork the Repository

  • Step 2: Click the Fork button at the top-right of the repository page.

  • Step 3: Choose your GitHub account as the destination for the fork.

  • Step 4: Now, you will have a copy of the repository in your GitHub account.

2. Set Up GitHub Integration with Jenkins

  • Step 1: Install the necessary Jenkins plugins:

    • Navigate to Manage Jenkins > Manage Plugins.

    • Under the Available tab, search for "GitHub Integration" and "Git" plugins, then install them.

  • Step 2: Create a new Jenkins job:

    • Go to New Item in Jenkins.

    • Select Freestyle Project and name it according to your project.

    • Under Source Code Management, select Git.

  • Step 3: Configure the Git repository:

    • Paste the URL of your forked GitHub repository.

    • Under Credentials, add your GitHub credentials (username and personal access token).

  • Step 4: Set up GitHub WebHooks for CI/CD:

    • Go to your forked repository on GitHub.

    • Navigate to Settings > Webhooks > Add webhook.

    • In the Payload URL field, add your Jenkins server URL followed by /github-webhook/ (e.g., http://your-jenkins-url/github-webhook/).

    • Choose the events you'd like to trigger the webhook on (usually, Push and Pull request events).

    • Click Add webhook.


What Are GitHub WebHooks?

    • GitHub WebHooks are a way for GitHub to notify Jenkins (or any other system) about events in your repository, such as code pushes, pull requests, etc.

      * When a specified event occurs, GitHub sends a POST request to the configured URL with data describing the event.

  • Why Are WebHooks Important in CI/CD?

    • WebHooks enables the automatic triggering of Jenkins jobs based on changes in your GitHub repository, ensuring continuous integration and deployment without manual intervention.

3. Ensure CI/CD Setup is Configured

  • Step 1: Set up build triggers in Jenkins:

    • In your Jenkins job configuration, under Build Triggers, check the box for the GitHub hook trigger for GITScm polling.
  • Step 2: Define build steps:

    • Add necessary build steps like shell scripts, Docker build, or deploying to a server based on your project’s requirements.
  • Step 3: Set up post-build actions:

    • You can add actions like notifying team members, pushing artifacts, or deploying to staging/production environments.


Task 2

  1. In the "Execute Shell" section of your Jenkins job, run the application using Docker Compose.

  2. Create a Docker Compose file for this project (a valuable open-source contribution).

  3. Run the project and celebrate your accomplishment! 🎉

Solution:

Step 1: Create a Docker Compose File

You'll need to create a docker-compose.yml file that defines the services required for your application. Here’s an example template:

version: '3.9'

services:
  web:
    image: "trainwithshubham/node-app-batch-6:latest"
    ports:
      - "8000:8000"

Step 2: Add the Docker Compose Command in Jenkins

Now, you’ll configure Jenkins to run the application using Docker Compose.

  1. Open Jenkins and navigate to your project.

  2. Configure the Jenkins Job:

    • Go to the Build section.

    • Select the Add Build step and choose Execute Shell.

    • In the command box, enter the following:

    docker compose up -d

This command will run the services defined in your docker-compose.yml file in detached mode.

  1. Save the Configuration.

Step 3: Run the Project

  • Trigger the Jenkins Job: Run the Jenkins job you configured. Jenkins will execute the shell command to bring up your application services using Docker Compose.

  • Verify the Application: Your application should run once the job is completed. You can verify it by accessing the application URL or checking the status of the Docker containers using:

      docker ps
    

💡
If you need help or have any questions, just leave them in the comments! 📝 I would be happy to answer them!
💡
If you found this post useful, please give it a thumbs up 👍 and consider following for more helpful content. 😊

Thank you for taking the time to read! 💚