I made a multibranch pipeline project in Jenkins. I need to use two repositories and both need credentials.
I created a Jenkinsfile in repository1:
n
Your GitSCM class instantiation is incorrect. You have created two UserRemoteConfig objects - one with a URL of 'git@bitbucket.org:BRNTZN/repository2.git' and one with a credentialsId of 'jenkinsmaster'. Instead you want one object with both properties set.
checkout([
$class: 'GitSCM', branches: [[name: '*/master']],
userRemoteConfigs: [[url: 'git@bitbucket.org:BRNTZN/repository2.git'],[credentialsId:'jenkinsmaster']]
])
Should be:
checkout([
$class: 'GitSCM', branches: [[name: '*/master']],
userRemoteConfigs: [[url: 'git@bitbucket.org:BRNTZN/repository2.git',credentialsId:'jenkinsmaster']]
])
Notice there are no brackets around the comma in the "userRemoteConfigs" section in the second case.
I had just ran into the same issue and connected up an Eclipse debugger to Jenkins to find the issue.
See git-plugin GitSCM does not support ssh credentials when using checkout in a Jenkinsfile (45007).