# #Day 27 Task: Jenkins Declarative Pipeline with Docker

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1708354856517/9e44600d-13c4-4fc4-a3c3-af655cbf2710.png align="center")

## 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**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1708354924429/56cabceb-051b-40fe-912e-c6864c85ad0c.png align="center")

### **Task 1:**

1. Create a docker-integrated Jenkins declarative pipeline
    
2. Use the above-given syntax using sh inside the stage block
    
3. 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
    

* **Step1:** Create a new pipeline project and named it node declarative
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1708355321839/4a222191-3846-4fa8-aa14-3fdfce7ec48b.png align="center")
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1708355931560/96a325bf-8028-4dc8-8747-9a51c9e54e3b.png align="center")
    
    *Step2:*\- Now in the "Project Configuration" section, we have to define a pipeline script in the definition.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1708356068487/69623b31-31ce-48d9-8fbe-7314832ca84a.png align="center")
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1708356185214/bb8e7dc4-152a-4a3e-b724-603a6925b303.png align="center")
    
    *Step3:*\-Click on Save and Build the application.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1708356252600/00b70ac2-e9cc-4265-b480-827430394a75.png align="center")
    
    Step4:-Once the build is completed we can check in the Console Output. We can see the pipeline is successful.
    
    Step5:-Now you check the multi-stage view by clicking on the “Full Stage View” on the project main page
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1708421065385/78e8db3b-f7d9-4a94-b003-f56f79e942d3.png align="center")
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1708421097349/1788dde3-0ab5-4156-a424-d1db572cbaef.png align="center")
    
    ### **Task 2:**
    
    * Create a docker-integrated Jenkins declarative pipeline using the docker groovy syntax inside the stage block.
        
    * You won't face errors, you can Follow **this documentation**
        
    * Complete your previous projects using this Declarative pipeline approach
        
        **Step1:-**Now we have to add a docker image in the Build stage
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1708421190402/0eec5cfd-1901-41f4-add8-67b144c0305d.png align="center")
        
        Step2:-Click on Save and then click on Build Now.
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1708421280327/43eb8eb4-8ca9-4a88-9f24-dca57bdeb829.png align="center")
