Reputation: 29
Am having a Jenkins server running on GCP-Linux Vm, I want to access a code from git's private repo, am trying to access it from my Jenkins pipeline code, how can I enter my git credentials in Jenkin pipeline code?
Upvotes: 3
Views: 10863
Reputation: 1140
you should share the pipeline you use for more specific answers.
As a general answer:
In this case no special reference in pipeline code is necessary
If you want to clone a second repository in your build you can use inside your pipeline:
pipeline {
environment {
gitCredentialId = 'Jenkins-Bitbucket' //defined in credentials area
gitUrl = 'https://bitbucket.org/companyNameHere/repoNameHere.git'
deployBranch = 'branch-name-here'
}
stages {
stage('Cloning Git') {
steps {
git(
url: gitUrl,
credentialsId: gitCredentialId,
branch: deployBranch
)
}
}
}
to store credentials: manage jenkins > manage credentials > click on global domain > add credential . Make sure to put meaningful description and ids as this area tends to become a mess in time and it is hard to cleanup as you will never know what can be deleted.
Each credential will tell you where it is used:
Upvotes: 2