Skip to main content

Command Palette

Search for a command to run...

Day 27 Task: Jenkins Declarative Pipeline with Docker ๐Ÿš€

Published
โ€ข2 min read
Day 27 Task: Jenkins Declarative Pipeline with Docker ๐Ÿš€
A

"I'm a 3rd-year Computer Engineering student at Marwadi University with skills in C++, web development (MERN stack), and DevOps tools like Kubernetes. I contribute to open-source projects and share tech knowledge on GitHub and LinkedIn. I'm learning cloud technologies and app deployment. As an Internshala Student Partner, I help others find jobs and courses." now currently focusing on #90DaysOfDevops

Day 26 was all about a Declarative pipeline, now its 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 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

How the Stages Look

Here's an example of how the stages might look in your Jenkins Declarative Pipeline:

pipeline
{
agent any
stages {
    stage('Build') {
        steps {
            sh 'docker build -t your-image-tag .'
        }
    }

    stage('Run') {
        steps {
            sh 'docker run -d your-image-tag'
        }
    }
    stage('Deploy') {
        steps {
            sh 'Deploy throught out cicd'
        }
    }
 }
}

Task 01: Create a Docker-Integrated Jenkins Declarative Pipeline

To create a Docker-integrated Jenkins Declarative Pipeline, follow these steps:

  1. Log In: Log in to your Jenkins server and navigate to the Jenkins home page.

  2. Create New Item: Click on the "New Item" button on the left-hand side of the screen to create a new Jenkins pipeline.

  3. Enter Item Name: In the "Enter an item name" field, type in a name for your new pipeline and select "Pipeline" as the project type.

  4. Continue: Click on the "OK" button to proceed.

  5. Configure Pipeline: On the next page, scroll down to the "Pipeline" section and select "Pipeline script" as the Definition.

  6. Define Pipeline Script: In the Script text area, use the following code and save it

pipeline
{
    agent any
    stages{
    stage("Code")
    {
        steps
        {
            git url : 'https://github.com/anand-raval-git/react_django_demo_app.git' , branch: 'main'
        }
    }
    stage("Build")
    {
        steps
        {
            sh 'docker build . -t anand-raval-git/react_django_demo_app'
        }
    }

    }
}

Step 2: Run the Jenkins Pipeline:

  1. To run the pipeline, click on the pipeline name on the Jenkins home page.

  2. Click on the "Build Now" button to start the pipeline.

    Check the output of the build:

Thankyou for reading !!!!!

90DaysOfDevops

Part 19 of 49

So In This Series I am following 90 DaysOfDevops challenge , what i will learn in my devops journey i will share with you with my blogs ,You will get blog on tools which used by devops engineer , example :- Linux,ansible,terraform,docker,etc

Up next

Day 26 Task: Jenkins Declarative Pipeline ๐Ÿš€

Some terms for your Knowledge What is Pipeline - A pipeline is a collection of steps or jobs interlinked in a sequence. Declarative: Declarative is a more recent and advanced implementation of a pipeline as a code. Scripted: Scripted was the first an...

More from this blog

A

Anand Raval

118 posts

Hello I am Anand Raval , i contributed my work in robotics(arduino uno) , fronted web devloper,competitive programming, now currently focusing on #90DaysOfDevops