Day #27 : Jenkins Declarative Pipeline with Docker

Getting Started

  1. Open Jenkins: Go to Jenkins in your web browser.

  2. Log In: If you're not logged in, enter your Jenkins credentials.

  3. Dashboard: You'll land on the Jenkins dashboard after logging in.

Creating a New Jenkins Job

  1. New Job: Look for an option like "New Item" or "Create New Job" on the dashboard and click it.

  2. Job Details:

    • Name: Give your job a name.

    • Type: Choose "Pipeline" as your job type.

Configure Pipeline

  • Save: Save your job configuration after entering the pipeline script.

    Use the following pipeline script:

      pipeline {
          agent any
    
          stages {
              stage('Cloning Repository') {
                  steps {
                      git 'https://github.com/theshubhamgour/node-todo-cicd.git'
                  }
              }
    
              stage('Build') {
                  steps {
                      sh 'docker build -t todo-cicd .'
                  }
              }
    
              stage('Testing') {
                  steps {
                      echo 'Testing Success'
                  }
              }
    
              stage('Deploying') {
                  steps {
                      sh 'docker-compose down'
                      sh 'docker-compose up -d'
                      sh 'docker run -dp 8000:8000 todo-cicd'
                  }
              }
          }
      }
    
  • Once you've configured your pipeline script, save your job configuration.

Building Your Pipeline

Trigger Build: Manually start a build or set up triggers for automatic builds on code commits.

Check Console Output: Monitor the progress of your pipeline by checking the "Console Output."

Verify Application: Make sure your application is working on port 8000.

  • You can manually trigger a build of your pipeline job or set up triggers based on events like code commits. it failed earlier because the port was already occupied so we killed the existing container and then the issue was resolved

Check the "Console Output"

  • Review the "Console Output" to monitor the progress of your pipeline.

Verify Application

  • Check whether the application is working on port 8000.

Concluding the Jenkins-Docker Integration

By combining Jenkins and Docker, we've simplified and accelerated our software development process. This integration ensures that our applications are built, tested, and deployed consistently. Developers can now deliver high-quality software faster and with confidence.