Using credentials from Jenkins store in a jenkinsfile

后端 未结 4 1852
轻奢々
轻奢々 2020-12-30 03:52

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         


        
4条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-30 04:12

    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).

提交回复
热议问题