Day 26 was all about a Declarative pipeline, now its time to level up things, let’s integrate Docker and your Jenkins declarative pipeline.
What is docker-integrated Jenkins declarative pipeline
Docker-integrated Jenkins declarative pipeline is a way of defining and executing continuous integration and continuous delivery (CI/CD) pipelines using the Jenkins automation server and the Docker containerization platform.
In this approach, the pipeline is defined in a declarative manner using a Jenkinsfile that specifies the stages, steps, and parameters of the pipeline. The pipeline can also make use of Docker containers to encapsulate the build, test, and deployment environment, ensuring consistency and reproducibility across different stages and environments.
Overall, the Docker-integrated Jenkins declarative pipeline provides a powerful and flexible approach to building, testing, and deploying software in a containerized environment, with the added benefits of automation, repeatability, and scalability.
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:
stages {
stage('Build') {
steps {
sh 'docker build -t trainwithshubham/django-app:latest'
}
}
}