Complete Jenkins CI/CD Project

Complete Jenkins CI/CD Project


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:
  3. Enable GitHub WebHooks – In GitHub, go to the repository settings and set up WebHooks to connect it to your Jenkins server.


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"]
        

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
        

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.

要查看或添加评论,请登录

Manit Singh的更多文章

社区洞察

其他会员也浏览了