Skip to content

Instantly share code, notes, and snippets.

@blaisep
Created October 20, 2016 23:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blaisep/63e2af6d3b7b32a2b69c4bccf0293df1 to your computer and use it in GitHub Desktop.
Save blaisep/63e2af6d3b7b32a2b69c4bccf0293df1 to your computer and use it in GitHub Desktop.
Insert Git Credentials using Jenkins Pipeline Script
Suppose you want to inject a credential into a Pipeline script.
The cloudbees note does not include Pipeline script examples.
https://support.cloudbees.com/hc/en-us/articles/203802500-Injecting-Secrets-into-Jenkins-Build-Jobs
The Jenkins Pipeline Docs' description of the `git push`method doesn't have an example using injected credentials.
(https://jenkins.io/doc/pipeline/examples/#push-git-repo)
The Snippet generator is helpful, but not not if you try to follow the instructions at:
https://wiki.jenkins-ci.org/display/JENKINS/Credentials+Binding+Plugin
If you have associated a credential with your Git repo, use the Snippet Generator to select the plain `Git` option and it will return a snippet with this gem.
```java
stage('Checkout') {
git branch: 'lts-1.532', credentialsId: '82aa2d26-ef4b-4a6a-a05f-2e1090b9ce17', url: 'git@github.com:jenkinsci/maven-plugin.git'
}
```
Note that the `credentialsID` is a cryptic string and not at all like the display name I originally expected.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment