Checkout Jenkins Pipeline Git SCM with credentials?

后端 未结 6 1705
情深已故
情深已故 2020-12-04 08:20

I was following this tutorial:

node {
  git url: \'https://github.com/joe_user/simple-maven-project-with-tests.git\'
  ...
}

However it doe

6条回答
  •  盖世英雄少女心
    2020-12-04 09:02

    For what it's worth adding to the discussion... what I did that ended up helping me... Since the pipeline is run within a workspace within a docker image that is cleaned up each time it runs. I grabbed the credentials needed to perform necessary operations on the repo within my pipeline and stored them in a .netrc file. this allowed me to authorize the git repo operations successfully.

    withCredentials([usernamePassword(credentialsId: '', passwordVariable: 'GIT_PASSWORD', usernameVariable: 'GIT_USERNAME')]) {
        sh '''
            printf "machine github.com\nlogin $GIT_USERNAME\n password $GIT_PASSWORD" >> ~/.netrc
            // continue script as necessary working with git repo...
        '''
    }
    

提交回复
热议问题