This repository contains a complete CI/CD pipeline setup using Jenkins that builds, tests, packages, and deploys a Node.js "Hello World" web application.
ci-1/
├── app/
│ ├── index.js # Express.js web server
│ ├── package.json # Node.js dependencies
│ └── test/
│ └── index.test.js # Jest unit tests
├── Dockerfile # Multi-stage Docker build
├── docker-compose.yml # Application deployment
├── docker-compose.jenkins.yml # Jenkins with Docker-in-Docker
├── Jenkinsfile # Declarative Jenkins pipeline
├── healthcheck.sh # Health verification script
├── .dockerignore
├── .gitignore
└── README.md
The demo application is a simple Express.js server that:
- Serves "Hello World" on the root endpoint (
/) - Provides a health check endpoint (
/health) returning JSON status - Runs on port 3000
- Docker and Docker Compose installed
- Jenkins (can be run via Docker Compose - see below)
- Git
-
Start Jenkins and the application:
docker-compose -f docker-compose.jenkins.yml up -d
-
Get Jenkins initial admin password:
docker exec jenkins cat /var/jenkins_home/secrets/initialAdminPassword -
Access Jenkins at
http://localhost:8080and complete setup -
Install required Jenkins plugins:
- Docker Pipeline
- Docker plugin
- NodeJS plugin Go to Manage Jenkins > Global Tool Configuration.
Scroll down to NodeJS and click Add NodeJS.
Give it a Name (e.g., node-22) and choose a version to install automatically.
Click Save.
-
Create a new Pipeline job in Jenkins:
- Select "Pipeline script from SCM"
- Set SCM to Git
- Repository URL: path to this repository
- Script Path:
Jenkinsfile
-
Run the pipeline
-
Ensure Docker and Docker Compose are available to Jenkins
-
Create a new Pipeline job:
- Select "Pipeline script from SCM"
- Set SCM to Git
- Repository URL: path to this repository
- Script Path:
Jenkinsfile
-
Run the pipeline
-
Build and run the application:
docker-compose up -d
-
Check health:
./healthcheck.sh
-
Access the application:
- Root:
http://localhost:3000 - Health:
http://localhost:3000/health
- Root:
The Jenkins pipeline includes the following stages:
- Build: Installs Node.js dependencies
- Test: Runs Jest unit tests
- Package: Builds Docker image
- Deploy: Deploys using Docker Compose
- Health Check: Verifies container is running and healthy
The health check script (healthcheck.sh) verifies:
- Container is running
/healthendpoint responds with status 200- Health endpoint returns valid JSON
Run tests locally:
cd app
npm install
npm testStop all services:
docker-compose down
# or for Jenkins setup:
docker-compose -f docker-compose.jenkins.yml down- The Jenkins container requires Docker socket access for Docker-in-Docker
- Jenkins data is persisted in a Docker volume
- The application container includes built-in health checks
- All Docker images use Alpine Linux for minimal size