It's 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 the sh docker build . -t <tag>
in your pipeline stage block to run the docker build command.
Docker run: you can use the 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'
}
}
}
Task 1
1) Create a docker-integrated Jenkins declarative pipeline
Set up the Jenkins server.
In Jenkins, Click on “New Item”, create a new pipeline job, and select "Pipeline" as the project type.
- In the configuration, In the pipeline script section, define your stages, steps, and parameters.
- Save and run the pipeline. You should see the pipeline execute each stage and run your application inside a Docker container.
- See the Console Output:
- 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 2
- 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.
- See the Console Output:
Hope you find this helpful. Thanks for Reading.
Happy learning !!!
Suggestions are always welcome.