This repository contains a demo project created as part of my DevOps studies in the TechWorld with Nana – DevOps Bootcamp.
https://www.techworld-with-nana.com/devops-bootcamp
Demo Project: CD - Deploy Application from Jenkins Pipeline to EC2 Instance (automatically with docker)
Technologies used: AWS, Jenkins, Docker, Linux, Git, Java, Maven, Docker Hub
Project Description:
- Prepare AWS EC2 Instance for deployment (Install Docker)
- Create ssh key credentials for EC2 server on Jenkins
- Extend the previous CI pipeline with deploy step to ssh into the remote EC2 instance and deploy newly built image from Jenkins server
- Configure security group on EC2 Instance to allow access to our web application
Complete the previous demo project first. The EC2 instance must be launched with Docker installed. See aws-module-9.1 for setup instructions.
Authenticate with Docker Hub before proceeding:
docker login
- Open Jenkins and navigate to Manage Jenkins → Plugins → Available plugins
- Search for and install SSH Agent
- Restart Jenkins if prompted
- Go to Dashboard → New Item
- Name it
aws-multibranch, select Multibranch Pipeline, click OK
- Click Add source → Git
| Field | Value |
|---|---|
| Credentials | github |
| Repository HTTPS URL | https://github.com/explicit-logic/aws-module-9.2 |
- Click Validate to confirm access
Click Add and include:
Discover branchesDiscover pull requests from origin
| Field | Value |
|---|---|
| Script Path | Jenkinsfile |
- Click Save — Jenkins will scan the repository and automatically create jobs for each branch
-
Navigate to the
aws-multibranchpipeline → Credentials → Add Credentials -
Fill in the following fields:
| Field | Value |
|---|---|
| Kind | SSH Username with private key |
| ID | aws-ec2 |
| Username | ec2-user |
| Private Key | Paste the contents of your .pem file (see below) |
To copy the private key content, run:
cat ~/.ssh/app-key.pem- The generated
ssh-agentcode snippet will look like:
sshagent(['aws-ec2']) {
// your SSH commands here
}See the full deployment code in
app/script.groovy—deployAppfunction
Update the EC2 instance's inbound rules to allow traffic from Jenkins:
- Go to EC2 → Security Groups → select your instance's security group
- Click Edit inbound rules → Add rule
| Type | Port | Source |
|---|---|---|
| SSH | 22 | <Jenkins-IP>/32 |
| Custom TCP | 8080 | 0.0.0.0/0 |
- Trigger the pipeline job in Jenkins
- Once complete, open your browser and navigate to:
http://<EC2_PUBLIC_IP>:8080


