0
votes

I am currently automating a project in Jenkins. I am using a pipeline that reads and executes a Jenkinsfile from a Source Management Tool (GIT in my case). For it to happen, I give the git URL and supply credentials with 'Jenkins Credentials Provider'and execute the build. It reads the Jenkinsfile and checks out the code, but fails at the next stage:

pipeline{
    agent any
    stages{
...
        stage('Cloning GIT Repo'){
            steps{
                echo 'Cloning the repository'
                git url: 'http://test.git'
            }
        }
...

It gives the error:

No credentials specified

It there a way for me to use the global credentials, I specified in the Jenkins UI earlier?

1

1 Answers

2
votes

You can use credentialsId param

git(
   url: 'http://test.git',
   credentialsId: 'jenkins-credentials',
   branch: "${branch}"
)

https://jenkins.io/doc/book/pipeline/jenkinsfile/#optional-step-arguments https://jenkins.io/doc/pipeline/examples/#push-git-repo