In this tutorial, we'll walk through the process of deploying a web application using Jenkins CI/CD declarative pipeline on Amazon Web Services (AWS). This step-by-step guide will cover setting up an AWS EC2 instance, installing Jenkins, configuring Docker, creating a Jenkins pipeline, and deploying the application.
Step 1: Create an EC2 Instance on AWS
Go to the AWS portal and log in.
Navigate to EC2 and click on "Launch Instance".
Choose an appropriate AMI (Amazon Machine Image) like Ubuntu, select the instance type as t2.micro, and configure security settings to allow HTTP and HTTPS traffic.
Create a new key pair or use an existing one and download the .pem file.
Step 2: Configure Security Groups
Find the security group associated with your EC2 instance and add inbound rules to allow ports 8080 and 8001.
Step 3: Connect to the EC2 Instance
Use SSH to connect to the EC2 instance by copying the SSH command from the server description.
Open a terminal in the directory where the .pem file is located and paste the SSH command to connect.
Step 4: Install Jenkins
- Follow the instructions here to install Jenkins on your EC2 instance.
Step 5: Install Docker
- Run the command
sudo apt-install docker.io
to install Docker on your EC2 instance.
Step 6: Verify Installation
- Check if Jenkins and Docker are installed by running
jenkins --version
anddocker --version
respectively.
Step 7: Create a Jenkins Pipeline
Go to the Jenkins dashboard and click on "New Item".
Name the project as "declarative_pipeline" and select "Pipeline" as the project type.
Add a description for the project and click on "OK".
In the pipeline script, define stages for checking out the code, testing, building Docker image, and running the container.
Step 8: Save and Build the Pipeline
Click on "Save" to save the pipeline configuration.
Click on "Build Now" to trigger the pipeline execution.
Step 9: Monitor Pipeline Progress
View the pipeline progress by clicking on "Stage View" to check the status of each stage.
Step 10: Access the Deployed Application
Once the pipeline execution is successful, search for the public IP address of the EC2 instance followed by port 8001 in your browser to access the deployed web application.
Congratulations! You have successfully deployed a web application using Jenkins CI/CD declarative pipeline on AWS. This process automates the deployment process, making it efficient and reliable. Happy coding!