Prerequisites
Before you begin, ensure you have:- AWS EC2 instance running Ubuntu
- GitHub account
- Basic understanding of Docker and Jenkins
Setup steps
Clone the repository
Clone the Jenkins pipeline repository to your local machine:The repository contains:
Jenkinsfile- Pipeline configurationDockerfile- Node.js application containerizationindex.js- Simple Express applicationpackage.json- Node.js dependencies
Install Jenkins on EC2
SSH into your EC2 instance and install Jenkins:Access Jenkins at
http://<your-ec2-public-ip>:8080 and complete the initial setup wizard.Configure Docker permissions
Install Docker and grant Jenkins user permission to use it:
Install Docker
Configure permissions
Install Jenkins plugins
In the Jenkins dashboard, navigate to Manage Jenkins > Manage Plugins and install:
- Docker plugin
- Pipeline plugin
- GitHub Integration plugin
Create Jenkins pipeline job
- Click New Item in Jenkins dashboard
- Enter a name (e.g., “nodejs-demo-app”)
- Select Pipeline and click OK
- In the Pipeline section, select Pipeline script from SCM
- Choose Git as SCM
- Enter repository URL:
https://github.com/mani-6666/Jenkins-Pipeline-for-CI-CD.git - Set branch to
*/main - Save the configuration
Configure GitHub webhook
Set up automatic builds when you push code to GitHub:
- Go to your GitHub repository settings
- Navigate to Webhooks > Add webhook
- Set Payload URL:
http://<your-ec2-public-ip>:8080/github-webhook/ - Content type:
application/json - Select Just the push event
- Click Add webhook
The webhook triggers the Jenkins pipeline automatically whenever you push commits to the repository.
Trigger your first build
You can trigger a build in two ways:Manual trigger:
- Click Build Now in your Jenkins job
- Make a change to your repository
- Commit and push to GitHub
- Jenkins will automatically start the pipeline
- Clone - Fetch code from GitHub
- Build - Create Docker image
- Test - Run npm tests
- Deploy - Launch Docker container
Verify deployment
Once the pipeline completes successfully:
- Check the Jenkins console output for “Pipeline completed!”
- Verify the Docker container is running:
- Access your application at
http://<your-ec2-public-ip>
Pipeline stages explained
The Jenkins pipeline defined inJenkinsfile includes:
Troubleshooting
Docker permission denied
Docker permission denied
If you see “permission denied while trying to connect to Docker daemon”:Wait a few seconds for Jenkins to restart, then retry the build.
Port already in use
Port already in use
If port 80 or 3000 is already in use:
Webhook not triggering builds
Webhook not triggering builds
Verify webhook configuration:
- Ensure Payload URL ends with
/github-webhook/ - Check security group allows inbound traffic on port 8080
- Review webhook delivery history in GitHub settings
Next steps
Setup Guide
Detailed setup instructions for each component
Pipeline Configuration
Learn about pipeline stages and customization
Troubleshooting
Common issues and solutions
AWS EC2 Setup
Complete EC2 instance configuration guide