Day 27 Task: Jenkins Declarative Pipeline with Docker

Day 27 Task: Jenkins Declarative Pipeline with Docker

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

  • In configuration, In the pipeline script section, define your stages, steps, and parameters.

    Save and run the pipeline. You should see the pipeline execute each stage and run your application inside a Docker container.

  • you can see console output

    You will face errors in case of running a job twice, as the docker container will be already created

    Thank you :)