git credentials

https://stackoverflow.com/questions/38461705/checkout-jenkins-pipeline-git-scm-with-credentials

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

checkout scm: ([
                    $class: 'GitSCM',
                    userRemoteConfigs: [[credentialsId: '******',url: ${project_url}]],
                    branches: [[name: 'refs/tags/${project_tag}']]
            ])
 
原文地址:https://www.cnblogs.com/i-shu/p/14722996.html