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 on EC2 Instance (automatically with docker-compose) Technologies used: AWS, Jenkins, Docker, Linux, Git, Java, Maven, Docker Hub
Project Description:
- Install Docker Compose on AWS EC2 Instance
- Create
docker-compose.ymlfile that deploys our web application image - Configure Jenkins pipeline to deploy newly built image using Docker Compose on EC2 server
- Improvement: Extract multiple Linux commands that are executed on remote server into a separate shell script and execute the script from Jenkinsfile
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
Reference: https://gist.github.com/npearce/6f3c7826c7499587f00957fee62f8ee9
Download the binary:
sudo curl -L https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-composeFix permissions:
sudo chmod +x /usr/local/bin/docker-composeVerify installation:
docker-compose versionSee ./docker-compose.yaml for the configuration that deploys the web application image.
Groovy deploy function:
deployAppin app/script.groovy
- Go to Dashboard → New Item
- Name it
aws-multibranch, select Multibranch Pipeline, click OK
Click Add source → Git and configure:
| Field | Value |
|---|---|
| Credentials | github |
| Repository HTTPS URL | https://github.com/explicit-logic/aws-module-9.3 |
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 |
To copy the private key content:
cat ~/.ssh/app-key.pem- Run the pipeline job.
Instead of embedding multiple remote commands inline in the Jenkinsfile, they are extracted into a dedicated shell script that gets copied and executed on the EC2 server.
Groovy deploy function:
deployScriptin app/script.groovy
Run the pipeline job to verify:

