Yogesh Jilhawar
Yogesh Jilhawar

Reputation: 6303

pass credentails to Jenkinsfile

I have Jenkinsfile written for my project which has number of stages, out of that, in one stage I need to clone my private git repo which needs creds to be passed in order to download the code. I am not getting any idea on how to pass these creds to clone repo. My Jenkinsfile would be like this-

pipeline {
agent any
environment {
      HOME_DIR = "$WORKSPACE/"
      }
stages {
stage('clone repos') {
  steps {
    **sh 'git clone http://<repo_url> '**
  }
}
}

I need to pass my creds to clone the repo. Does anyone has any idea about passing creds?? any help is highly appreciated.

Upvotes: 0

Views: 212

Answers (1)

Mithun Biswas
Mithun Biswas

Reputation: 1833

First create a credential with your git username and password. then use the credential id in the Jenkins file.

Steps

Click the Credentials link in the sidebar

Click on the Global credentials domain

Click [Add Credential]

Select a credential kind that can be used from your build jobs.

Username with password - a username/password pair

pipeline {
agent any
stages {
stage('clone repos') {
  steps {

   dir ("example"){                 
        git branch: 'master', credentialsId: 'your_credential_id', url: 'https://github.com/jenkinsci/examples.git'

    }
  }
}
}

Upvotes: 1

Related Questions