Using credentials from Jenkins store in a jenkinsfile

后端 未结 4 1831
轻奢々
轻奢々 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:11

    What kind of credentials do you use?

    I suggest that you use SSH credentials (i.e. private/public keys):

    1. Generate a SSH key pair (make sure you generate it for the correct username!)
    2. Add your public SSH key to your Bitbucket account
    3. Configure your Jenkins to use your newly created SSH private key, as shown in the example below:

    Then you need to use SSH URL as connection to your Git your credentials in your pipeline (instead of HTTP URL), as follows:

    checkout([
        $class: 'GitSCM', branches: [[name: '*/master']],
        userRemoteConfigs: [[url:'ssh://BRNTZN@bitbucket.org:BRNTZN/repository2.git'],[credentialsId:'jenkins_ssh_key']]
    ])
    

    Also, note that you might want to set a specific id for your credentials (e.g. jenkins_ssh_key or BRNTZN_ssh_key) to improve readability and simplify pipeline configuration.

提交回复
热议问题