Skip to main content

Command Palette

Search for a command to run...

Day 26: Jenkins Declarative Pipeline with Docker

Published
โ€ข2 min read
Day 26:  Jenkins Declarative Pipeline with Docker

Hello DevOps Community! ๐Ÿš€

Welcome to Day 26 of our #90DaysOfDevOps journey. Yesterday, we explored Jenkins Declarative Pipelines, and today, we're taking it a step further by integrating Docker into our Jenkins pipeline. This integration will help automate the build and deployment process of Docker containers, streamlining your CI/CD pipeline even more. Letโ€™s dive in! ๐Ÿ˜

Why Integrate Docker with Jenkins?

Docker allows us to package applications into containers, ensuring consistency across different environments. Integrating Docker with Jenkins Declarative Pipelines makes it easier to automate the build, test, and deployment processes, providing a seamless CI/CD experience.

Task : Creating a Docker-Integrated Jenkins Declarative Pipeline

Step-by-Step Guide

  1. Open Jenkins Dashboard:

    • Go to your Jenkins dashboard and create a new Pipeline job.
  2. Define Your Pipeline:

    • In the Pipeline section, define your pipeline script using the following syntax:
    pipeline {
        agent any
        stages {
            stage('Build') {
                steps {
                    sh 'docker build -t yourdockerhubusername/your-app:latest .'
                }
            }
            stage('Run') {
                steps {
                    sh 'docker run -d yourdockerhubusername/your-app:latest'
                }
            }
        }
    }

Explanation:

  • agent : Runs the pipeline on agent.

  • stages: Defines the stages in your pipeline.

  • stage('Build'): Builds the Docker image.

  • stage('Run'): Runs the Docker container.

Conclusion

By integrating Docker with Jenkins Declarative Pipelines, youโ€™re automating the build and deployment process, making your CI/CD pipeline more efficient. This approach not only saves time but also ensures consistency across environments.

Keep experimenting and refining your pipelines, and donโ€™t forget to document your process. Happy coding! ๐ŸŽ‰


Stay tuned for more exciting tasks as we continue our #90DaysOfDevOps journey. Keep pushing your limits and sharing your progress. Letโ€™s grow together! ๐Ÿš€

More from this blog

Gunjan's blog

34 posts