Skip to main content

Command Palette

Search for a command to run...

Day 27 : Jenkins Declarative Pipeline with Docker

Updated
2 min read

we will create our Declarative pipeline with docker Today. Let's Start.

Before starting you should have Jenkins and docker installed in your system. If not then please go through my previous blogs.

Step 1 ) Go to your Jenkins dashboard and select new item. Add name for your pipeline and select Pipeline and click okay.

Step 2) Add Description of it and select Githhub project and add url of it.

we will use https://github.com/patelajay745/react_django_demo_app for this project.

step 3 ) You do not need to select other option . Just go below and write pipeline script as below.

pipeline {
    agent any

    stages {
        stage('checkout') {
            steps {
                git url : "https://github.com/patelajay745/react_django_demo_app.git", branch : "main"
            }
        }
        stage('build') {
            steps{
                sh 'docker build . -t react-django-app:latest'
            }
        }
        stage('Deploy') {
            steps{
                sh 'docker run -d -p 8001:8001 react-django-app:latest'
            }
        }
    }
}

Step 4) Click Save. Now when you press Build Now from left panel. Your stage view will look like below screenshots if everything was right.

You can check your console output, if it gets failed , to see what went wrong.

Congratulations that was it for the Declarative pipeline.

You can build this using docker compose also. you just need to change your pipeline screen as below.

and your stage view will look like this

That was all for today's task. If you have any questions/suggestions please comment below. See you another day.

#Jenkins #DeclarativePipeline #Docker #ApplicationDeployment #CI/CD #DevOps #Automation #SoftwareDevelopment #Containerization #DevOpsTools #StreamlinedDeployment

More from this blog

Ajay Patel

116 posts