Table of contents
This is a blog related to how to write Jenkins Pipeline as code in Pipeline Script.
Docker Build and Docker Run
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'
}
}
}
Task-01
Create a docker-integrated Jenkins declarative pipeline.
Creation of Declarative Pipeline
You can give a Description to this of what you have created
Use the above-given syntax using sh
inside the stage block.
Console Output
Snapshot of Pipeline Success
Task-02
Create a docker-integrated Jenkins declarative pipeline using the docker
groovy syntax inside the stage block.
Note: If someone is getting an error like this you can use following steps,
workflowscript: 11: invalid agent type "docker" specified. must be one of [any, label, none] @ line 11, column 17. docker{
error!!!
Dashboard >> Manage Jenkins >> Available Plugins >> Download Docker Pipeline and Docker Plugins.
Description of Declarative Pipeline using Docker
Pipeline Script
Console Output
Snapshot of Pipeline Success