Declarative Pipeline with docker
1 min read
Task 1
Create a docker-integrated pipeline with docker
Docker builds: use sh 'docker build. -t <tag> ' to run the docker build command.
Docker run: use sh 'docker run -d <image>' in your pipeline
to stage block to run the container.
Now, Steps to do it.Let's Start
create a pipeline
use sh syntax in stage block
pipeline{ agent any stages{ stage("Code Clone"){ steps{ git branch : 'master', url:'https://github.com/sri766/node-todo-cicd.git' } } stage("Code Build"){ steps{ sh 'docker build . -t django-node-todo:latest ' } } stage("Code Testing"){ steps{ echo 'testing' } } stage("code Deploy"){ steps { sh 'docker run -d -p 8000:8000 django-node-todo:latest' } } } }
save and run the pipeline.
console output -
app Is running at port 8000.
Task 2
we can create declarative pipeline with docker by using groovy syntax.
replacing deploy code with docker compose up and down command.
stage("code Deploy"){ steps { sh 'docker-compose down' sh 'docker-compose up' } }
#possible error may come:
permission denied to run docker commands: just give sudo permission to jenkins by adding sudo to sh commands.
webhooks 403 error: it can be managed. go to manage userProfile-> configure ->generateToken
copy it and add it to secret while adding webhooks to github.