# Project : Jenkins Declarative Pipeline: From Code to Production - Effortless Web App Deployment

Project Description: Automate the deployment process of a web application using Jenkins and its declarative syntax. This pipeline includes stages for building, testing, and deploying to a staging environment. It also performs acceptance tests and, upon success, deploys to production. Easy and efficient CI/CD from code to production.

Prerequisite:

1. EC2 Instance (Ubuntu) on AWS.
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690260533206/984dfbca-86ba-4d72-b99e-440e219cfed7.png align="center")

1. Jenkins installed on the EC2 Instance.
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690260797983/762e4962-6735-4c66-8657-b25c75883f9b.png align="center")

If you encounter any issues during the installation of Jenkins, you can refer to the following website for guidance: [**https://www.jenkins.io/doc/book/installing/linux/**](https://www.jenkins.io/doc/book/installing/linux/)

1. Docker and Docker-compose installed on the EC2 Instance.
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690260972794/2fc653ec-b5de-485e-9620-e418e9dafb50.png align="center")

If Docker and Docker-compose are not already installed, you can do so by executing the following command:

```bash
sudo apt-get install docker.io docker-compose
```

Add your Jenkins user to the Docker group by running the following commands:

```bash
sudo usermod -aG docker jenkins
sudo service jenkins restart
```

Now Let's get started.

Step - 1 : Goto Jenkins dashboard and click on "New Item "

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690261307617/2859738c-451e-4070-8085-b434e6f918ea.png align="center")

Step - 2 : Name your project and choose the pipeline option.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690261376081/afb3817b-034a-49de-b020-a3c77b3c553f.png align="center")

Step - 3 : Use the provided pipeline script to define stages for checkout, testing, building, and deployment.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690261490760/29bbe496-93e4-4d6c-bcf5-cb1544a09c54.png align="center")

```bash
pipeline {
    agent any

    stages {
        stage('checkout') {
            steps {
                git branch : 'main',url:'https://github.com/patelajay745/react_django_demo_app.git'
            }
        }
        stage('Test') {
            steps {
                echo 'testing'
             }
        }
        stage('Build') {
            steps {
                sh 'docker build --no-cache -t demo_app .'
             }
        }
        stage('Deploy') {
            steps {
                sh "docker run -p 8001:8001 -d demo_app"
             }
        }
    }
}
```

Here I have used this repo for the project : [https://github.com/patelajay745/react\_django\_demo\_app](https://github.com/patelajay745/react_django_demo_app)

Step - 4 : Save the pipeline configuration.

Step - 5 : Click "Build Now" to initiate the pipeline and monitor progress in "Stage View."

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690266082155/60334bdb-9057-46ce-86ce-4ad4ba9ce87a.png align="center")

Once all stages succeed, access your app at :

[http://Your-public-IP:8001/](http://18.224.55.44:8001/)

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690266190376/64f29749-85b2-4f3c-a67b-6cc57439ab8b.png align="center")

Congratulations! You've successfully implemented Jenkins Declarative CI/CD pipeline. If you have any questions or face any issues, feel free to ask in the comments. Happy Deploying!
