Complete Jenkins CI/CD Project πŸš€

Complete Jenkins CI/CD Project πŸš€

Β·

2 min read


πŸ› οΈ Step 1: Fork a Node.js Repository

  1. Choose a Node.js repository – Select a sample Node.js project. Look for a basic app or a CRUD application that is suitable for CI/CD.

  2. Fork the Repository – Create a fork of the selected repository. This forked repository will hold your code for the CI/CD setup.


πŸ”— Step 2: Set Up GitHub Integration with Jenkins

  1. Create a Jenkins Job – In Jenkins, create a new pipeline or freestyle project job for your CI/CD pipeline.

  2. Connect GitHub to Jenkins:

    • Go to the Jenkins job settings and select the "Source Code Management" section.

    • Add your forked GitHub repository URL.

  3. Enable GitHub WebHooks – In GitHub, go to the repository settings and set up WebHooks to connect it to your Jenkins server.

    • This allows Jenkins to automatically detect changes in your repository and trigger builds.

πŸ“ Step 3: Configure Your Jenkins Pipeline

  1. Pipeline Script or Freestyle Job – If using a freestyle job, add build steps under the β€œBuild” section. For a pipeline job, use a Jenkinsfile.

  2. Shell Commands in Jenkins – In the "Execute Shell" section, use Docker Compose commands to build and run your application:

     docker-compose up -d --build
    
    • This command will start your app using Docker Compose, creating and running containers for each service defined in your docker-compose.yml.

🐳 Step 4: Create a Docker Compose File

  1. Dockerfile – In the project’s root, ensure a Dockerfile is present. It should install dependencies, copy the code, and expose necessary ports. Example Dockerfile:

     FROM node:14
     WORKDIR /app
     COPY package*.json ./
     RUN npm install
     COPY . .
     EXPOSE 3000
     CMD ["npm", "start"]
    
  2. docker-compose.yml – Create a docker-compose.yml file that defines the services needed. Example docker-compose.yml:

     version: '3'
     services:
       app:
         build: .
         ports:
           - "3000:3000"
         environment:
           NODE_ENV: production
    
    • This file specifies the application service and any necessary configurations.

πŸš€ Step 5: Run the Jenkins Pipeline

  1. Trigger the Build – Push changes to the forked repository or trigger the build manually in Jenkins.

  2. Watch Jenkins Logs – Check the Jenkins console output to view the build, test, and deployment logs.

  3. Verify Deployment – Once Jenkins completes the build, your Node.js app should be running in a Docker container on the specified port.


Β