Day 27 Task: Jenkins Declarative Pipeline with Docker
#90DAYSOFDEVOPSCHALLENGE
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.
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 basanagoudapatil02/django-app:latest'
}
}
}
Task-01
- Create a docker-integrated Jenkins declarative pipeline
- Login to Jenkins and click on new item, Provide desired name and select “Pipeline” and click on “Ok” button.
2. Use the below-given syntax using sh inside the stage block
pipline {
agent any
stages{
stages('code'){
steps{
git url:'https://github.com/Basanagoudapatil02/django-todo.git',branch 'main'
}
}
stage('Build'){
Steps{
sh'docker build . -t react-django-docker-img:latest'
}
}
stage('Test'){
Steps{
echo "Testing"
}
}
stage('Deploy'){
Steps{
sh "docker run -d react-django-docker-jenkins -p 8001:8001 react-django-docker-img:lastest"
}
}
}
}
3. Click on Save. Click on “Build Now”.
- 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
- Run the pipeline once again by clicking on the “Build Now” button from the dashboard.
2. Error will pop up when we run the same job twice.
Task-02
- Create a docker-integrated Jenkins declarative pipeline using the docker groovy syntax inside the stage block.
Click on Save and then click on Build Now.
Happy Learning:)
I Hope you find this article useful.
Thank you so much for taking time to read my article.
Basanagouda Patil
Click here to check the LinkedIn Post…