DEV Community

Cover image for Day 27 Task: Jenkins Declarative Pipeline with Docker
On-cloud7
On-cloud7

Posted on

3 1 1 1 1

Day 27 Task: Jenkins Declarative Pipeline with Docker

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

stages {
        stage('Build') {
            steps {
                sh 'docker build -t devops/django-app:latest'
            }
        }
    }
Enter fullscreen mode Exit fullscreen mode

Task-01:
1)Create a docker-integrated Jenkins declarative pipeline
Step 1: In Jenkins, Click on New Item, and select "Pipeline" as the new job type.

Image description

Image description

Step 2: Configure Pipeline:

After selecting Pipeline, you will select a section where you can define the pipeline configuration.

Pipeline Script: This is a simple script editor where you can write your pipeline script directly.

**Pipeline from SCM: **You can define your pipeline script in a version control repository (e.g., Git) and have Jenkins fetch and execute it.

Image description

Image description

Step 3: Now go to Jenkins Pipeline and Build the Pipeline.

Image description

Step 4: Access your application on the browser as shown below

Image description

Step 5: It's working. Now if we run the job again it will fail because Jenkins tries to build a container but as we already have a running container with the same name and the same exposed port, creates a conflict. To see this click on build now and see the console output.

Image description

Task-02:

1)Create a docker-integrated Jenkins declarative pipeline using the docker groovy syntax inside the stage block.

We already have a docker-compose.yml configuration file in our repository, so we have to use docker-compose commands to up and down the service containers.

Image description

Click on Save and then click on Build Now

Image description

Image description

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay