Day 24 Task: Complete Jenkins CI/CD Project

Day 24 Task: Complete Jenkins CI/CD Project

Let’s build a complete CI/CD pipeline for your Node.js application! 🚀

How’s Day 23 coming along?

Day 23 focused on mastering the basics of Jenkins CI/CD. Today, you’ll elevate your skills by creating a full CI/CD pipeline project from start to finish.

Since you’ve already worked with Docker and Docker Compose, this project will integrate those tools into a real-world workflow. Ready to dive in and make it happen?

Step 1: Fork the Repository

  1. Go to the GitHub repository: node-todo-app

  2. Click the Fork button located in the top-right corner of the page.

  3. Congratulations! You now have your own copy of the repository!

Step 2: Set Up SSH Keys

  1. Open your terminal or command prompt.

  2. Generate an SSH key pair by running the command

     ssh-keygen
    
  3. When prompted:

    • Specify the file location to save the key (or press Enter to accept the default location, typically ~/.ssh/id_rsa).

    • Enter a passphrase (optional but recommended) for added security.

  4. The result will be two files:

    • Private Key: id_rsa (keep this secure!)

    • Public Key: id_rsa.pub.

Step 3: Add the SSH Key to GitHub

  1. Copy the contents of the public key:

      cat ~/.ssh/id_rsa.pub
    
  2. Go to GitHub > Settings > SSH and GPG Keys > New SSH Key.

  3. Paste the copied public key into the "Key" field.

  4. Click Add SSH Key.

    E.g.:-

Step 4: Install the GitHub Plugin in Jenkins

  1. Go to Jenkins > Manage Jenkins > Manage Plugins.

  2. Under the Available tab, search for GitHub Plugin.

  3. Select it and click Install Without Restart.

  4. Wait for the installation to complete.

Step 5: Create a New Jenkins Job

  1. In Jenkins, click on New Item.

  2. Enter an item name for your job (e.g., Node-ToDo-App).

  3. Select Freestyle Project and click OK.

Step 6: Configure Source Code Management

  1. Inside your Jenkins job configuration:

    • Go to the Source Code Management section.

    • Select Git.

  2. Enter the Repository URL:

    • Use the SSH URL of your forked repository (e.g., git@github.com:<your-username>/node-todo-app.git).
  3. Add Credentials:

    • Click Add > Jenkins.

    • Choose SSH Username with Private Key.

    • Enter your GitHub username and paste the contents of your private key (id_rsa).

    • Save.

      E.g.:-

Step 7: Test Jenkins and GitHub Connection

  1. Save the configuration and click Build Now in your Jenkins job.

  2. Verify that Jenkins successfully clones the repository without errors.

Step 8: Manually executed the Node.js project by following these steps:

  1. Installed Node.js: Ran the command to install Node.js, which is required to run the application:

sudo apt install nodejs

  1. Installed npm (Node Package Manager):
    Installed npm to manage dependencies for the project:sudo apt install npm

  1. Installed Project Dependencies: Used npm to install all dependencies listed in the package.json file:

sudo npm install

  1. Started the Application:
    Ran the application using the Node.js runtime:

node app.js

Output:- The application is running on the server's public IP address, accessible via port 8000.