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

Image of Datadog

How to Diagram Your Cloud Architecture

Cloud architecture diagrams provide critical visibility into the resources in your environment and how they’re connected. In our latest eBook, AWS Solution Architects Jason Mimick and James Wenzel walk through best practices on how to build effective and professional diagrams.

Download the Free eBook

Top comments (0)

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More