I have a script which contains git clone, however I saved the credentials using jenkins UI under jenkins credentials so whenever I check out normally I use withcredential, so how can I run the script that contains git clone in this case?
I tried to use withcredentials and then running the script inside it but it gives me permission denied
1
This syntax has been working for me. The credentials are stored in the Jenkins Global Credential store, whereas the GIT_CREDENTIAL_ID
is the ID defined by yourself, the GIT_USERNAME
is x-token-auth
and GIT_PASSWORD
is the access token.
steps {
dir('project_dir') {
script {
withCredentials([usernamePassword(credentialsId: 'GIT_CREDENTIAL_ID', usernameVariable: 'GIT_USERNAME', passwordVariable: 'GIT_PASSWORD')]) {
bat '''
git clone [...]
'''
}
}
}
}