<p>Can anyone share Jenkin file or steps to create CI/CD for bitbucket private repository to jenkin.</p>

<p>Build docker images and upload to docker hub and deploy to kubernetes.</p>

<p>i have try downloading plugin for bit bukcet no help so far.</p>

<p>I have not much-used Jenkin pipeline i have used freestyle project not much experience on Jenkin help appreciated.</p>

<pre><code>pipeline {

  environment {
    registry = "*******/test_case"
    registryCredential = 'dockerhub'
  }
  agent any
  stages {
    stage('Cloning Git') {
  steps {
    git 'https://harshmanvar@bitbucket.org/harshmanvar/configuring-ci-cd-on-kubernetes-with-jenkins.git'
  }
}

    stage('Docker Build') {
      steps {
        sh "docker build -t ****/test_case:${env.BUILD_NUMBER} ."
      }
    }
    stage('Docker Push') {
      steps {
        withCredentials([usernamePassword(credentialsId: 'dockerhub', passwordVariable: 'dockerHubPassword', usernameVariable: 'dockerHubUser')]) {
          sh "docker login -u ${env.dockerHubUser} -p ${env.dockerHubPassword}"
          sh "docker push ******/test_case:${env.BUILD_NUMBER}"
        }
      }
    }
    stage('Docker Remove Image') {
      steps {
        sh "docker rmi ********/test_case:${env.BUILD_NUMBER}"
      }
    }
    stage('Apply Kubernetes Files') {
      steps {
          withKubeConfig([credentialsId: 'kubeconfig']) {
          sh 'cat deployment.yaml | sed "s/{{BUILD_NUMBER}}/$BUILD_NUMBER/g" | kubectl apply -f -'
          sh 'kubectl apply -f service.yaml'
        }
      }
  }
}
post {
    success {
      slackSend(message: "Pipeline is successfully completed.")
    }
    failure {
      slackSend(message: "Pipeline failed. Please check the logs.")
    }
}
}
</code></pre>

<p>in first step it's not cloing repo while my repo is open not private.</p>

<p>Thanks</p>

Harsh Manvar
<p>Whether your git repository private or not, just setup your private access token in git developer setting and add it to the Jenkins credential. After that try this script <code>cloning Git</code> stage:</p>

<pre><code>stage('Cloning Git') {   
  steps {
    git credentialsId:'Your_Credential_Id', 
    url:'https://harshmanvar@bitbucket.org/harshmanvar/configuring-ci-cd-on-kubernetes-with-jenkins.git', branch:'master'
   }}
</code></pre>

<p>I hope this will be helpful to you.!</p>
