Day 27 : Jenkins Declarative Pipeline with Docker

Rahul SinghRahul Singh
2 min read

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

Task-01

  • Create a docker-integrated Jenkins declarative pipeline

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

  1. Login into Jenkins account create a new pipeline project and select the project from github

    1. In the pipeline script we are using groovy syntax for building docker image, pushing the image to docker hub and running the container. Since for pushing the image, we need to login into docker hub and hardcoding user name and password in pipeline script is not good security practice therefore we will save the credentials in Jenkins and use it as environment variable in our script

      1. For pushing the image to docker hub we need to call the credentials using groovy syntax as below

      2. After creating the script, we initiate building the pipeline

        1. The pipeline is created successfully and we will try to access the website and see if it is running properly or not

          1. The stages for pipeline will be based on how many stages you define in pipeline script. Here I have defined 3 stages build, test, deploy

0
Subscribe to my newsletter

Read articles from Rahul Singh directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Rahul Singh
Rahul Singh