Day 27 : Jenkins Declarative Pipeline with Docker


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
Login into Jenkins account create a new pipeline project and select the project from github
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
For pushing the image to docker hub we need to call the credentials using groovy syntax as below
After creating the script, we initiate building the pipeline
The pipeline is created successfully and we will try to access the website and see if it is running properly or not
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
Subscribe to my newsletter
Read articles from Rahul Singh directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
