Jenkins Declarative Pipeline with Docker (05) : Day - 43

ยท

2 min read

Table of contents

Day 26 was all about a Declarative pipeline, now its time to level up things, let's integrate Docker and your Jenkins declarative pipeline

Use your Docker Build and Run Knowledge

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

Copy

Copy

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

Task-02

  • Create a docker-integrated Jenkins declarative pipeline using the docker groovy syntax inside the stage block.

  • You won't face errors, you can Follow this documentation

Steps:

  1. Creating a two-tier-flask-app job in Jenkins with a declarative pipeline.

  2. Add GitHub project URL.

  3. Select Build Trigger types

  4. Enable Webhooks from the GitHub flask app repository and add Jenkins server URL as payload URL.

  5. Refresh the page to see the webhook added.

  6. Add docker credentials in Jenkins and create an ID for that credentials

  7. Write pipeline steps with the docker

  8. two-tier-flak-app deployed successfully

  9. Image is pushed on DockerHub

  10. Able to access two-tier-flask-app

"Thank you for reading my blog! Happy Learning!!!๐Ÿ˜Š

Stay tuned for more DevOps articles and follow me on Hashnode and connect on LinkedIn (linkedin.com/in/namratakumari04 for the latest updates and discussions.

ย