Day-27: Jenkins Declarative Pipeline with Docker

Day-27: Jenkins Declarative Pipeline with Docker

Docker Build and Docker Run

docker build - you can use sh 'docker build . -t <tag>' in your pipeline stage block to run the docker build command. (Make sure you have docker installed with correct permissions.

docker run: you can use sh 'docker run -d <image>' in your pipeline stage block to build the container.

How will the stages look

stages {
        stage('Build') {
            steps {
                sh 'docker build -t trainwithshubham/django-app:latest'
            }
        }
    }

Task-01

  • Create a docker-integrated Jenkins declarative pipeline

  • Use the above-given syntax using sh inside the stage block

  • You will face errors in case of running a job twice, as the docker container will be already created, so for that do task 2

Create a pipeline project.

Configure the pipeline by writing the groovy script for the node app.

 pipeline {
     agent any

     stages {
         stage('Code Fetch') {
             steps {
                 git 'https://github.com/ITAbhishekYadav/node-todo-cicd.git'
             }
         }
         stage('Build'){
             steps {
                 sh 'docker build . -t abhi/node-todo-app:latest'
             }
         }
         stage('Run'){
             steps {
                 sh 'docker run -d -p 8000:8000 abhi/node-todo-app:latest'
             }
         }
     }
 }

Save and click on Build now.

Check the output of the build.

Now, you can use the URL to check if the application is live.

......