Subscribe Us


Breaking

Recent In Voip

Popular

Comments

Recent

Automating Integration & Deployment Using Git, Jenkins and Docker Part 6 /Creating Build and Deploy Pipelines

 

1.Login to Jenkins portal. 
Then Click on New Items.


Enter the name of our Pipeline, In this case I have selected Build and Then choose pipeline.


Then Click on Ok.
Now In pipeline script, please paste the following script. Please make sure to put docker hub repository
URL in code in place of “put-your-docker-hub-registry-url” and in place of “docker” please use docker
hub credentials we configured earlier in global credentials of Jenkins 
And put GIT hub Repository URL in place of  “https://github.com/your-git-hub-repository.git”


 pipeline {
  environment {
    registry = " put-your-docker-hub-registry-url "
    registryCredential = 'docker'
    dockerImage = ''
  }
  agent any
  stages {
    stage('Cloning Git') {
      steps {
        git ''https://github.com/your-git-hub-repository.git '
      }
    }
    stage('Building image') {
      steps{
        script {
          dockerImage = docker.build registry + ":latest"
        }
      }
    }
    stage('Deploy Image') {
      steps{
        script {
          docker.withRegistry( '', registryCredential ) {
            dockerImage.push()
          }
        }
      }
    }
    stage('Remove Unused docker image') {
      steps{
        sh "docker rmi $registry:latest"
      }
    }
  }
}


Jenkins job build trigger.

  1. Go to your Jenkins job
  2. In Build Triggers section, check out: GitHub hook trigger for GITScm polling



And the Click on Apply and Save.
Running this Job will pull Docker file from Git Hub repository provided, Build docker image of app and
the push it to docker hub repository.


Deploying we will configure we will configure Jenkins (Deploy Job Pipeline ). 
Then Click on New Items.


Enter the name of our Pipeline, in this case I have selected Deploy and Then choose pipeline.


Then click ok .
Now go to pipeline script and paste following code . 
Now In pipeline script, please paste the following script. Please make sure to put docker hub
repository URL in code in place of “put-your-docker-hub-registry-url” and in place of “docker”
please use docker hub credentials we configured earlier in global credentials of Jenkins 
And put GIT hub Repository URL in place of  “'https://github.com/your-git-hub-repository.git”


 pipeline {
  environment {
    registry = "put-your-docker-hub-registry-url"  
    registryCredential = 'docker'
    dockerImage = ''
  }
  agent any
  stages {
    stage('Cloning Git') {
      steps {
        git 'https://github.com/your-git-hub-repository.git'  )
      }
    }
     
    stage('Integrate Test') {
     steps {
        sh "sudo docker-compose rm -f" 
        sh "sudo docker-compose pull "
        sh "sudo docker-compose up --build -d &"
     }
    }
  }
}




Jenkins job build trigger.

  1. Go to your Jenkins job
  2. In Build Triggers section, check out: Build after other projects are built
In project to watch enter Deploy.


Now click on Save .


Integrating Docker Hub registry with Jenkins.


1.Create a account at Docker Hub .
Just visit https://hub.docker.com/ and the follow the process to create a account.
2. After creating account just login into Docker Hub. Once you have successfully just click on the create 
Repository .


3.select a repository name. In this case I have chosen tutorial .


4.If you want to make your repo private you can chose private. Here in this case I have chosen public 
And then click on create.




5.Now go to Jenkins. Click on Manage Jenkins .


6.Click on configure credentials.




7.Now in the left-hand side click on Credentials.


8.Now click on Jenkins as highlighted.
9.Now click on Global Credentials.




10.Now click on add credentials as Highlighted.


Fill the below with you docker hub credentials and Password and the click ok .
Once There will be change in Git hub repository A docker image will be build and later app will be
deployed .
We will discuss about app and other component detail in next part.

0 on: "Automating Integration & Deployment Using Git, Jenkins and Docker Part 6 /Creating Build and Deploy Pipelines"