Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Insert git credentials into Jenkins Pipeline Script projects

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 pushmethod 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.

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.

@mramanathan

This comment has been minimized.

Copy link

@mramanathan mramanathan commented Apr 14, 2017

Cool tip!!! 👍

@denisdbell

This comment has been minimized.

Copy link

@denisdbell denisdbell commented Jun 14, 2017

Very good tip. Saved me a great deal of time

@vishveshv

This comment has been minimized.

Copy link

@vishveshv vishveshv commented Feb 5, 2018

Thanks for the tip 👍

@AJEETRAI707

This comment has been minimized.

Copy link

@AJEETRAI707 AJEETRAI707 commented Feb 13, 2019

it did not worked in my case.

@AJEETRAI707

This comment has been minimized.

Copy link

@AJEETRAI707 AJEETRAI707 commented Feb 13, 2019

my issue is how to configure and user git clone,git commit,git add ,in jenkinsfile and also by passing git credentials in jenkinsfile.

@dldude

This comment has been minimized.

Copy link

@dldude dldude commented May 14, 2019

Awesome tip 👍

@kanwal-tq

This comment has been minimized.

Copy link

@kanwal-tq kanwal-tq commented Aug 8, 2019

You have NO idea how much this helped me! Spent 2 days figuring out keys and credentials! Thanks a lot!!

@falcon68

This comment has been minimized.

Copy link

@falcon68 falcon68 commented Sep 18, 2019

Thank you so much. With this tip I needed just 10 min. to set up. Thanks

@aadityao1

This comment has been minimized.

Copy link

@aadityao1 aadityao1 commented Feb 1, 2020

is credentialid some kind of private or security credentials
which should not be publically available for everyone

@blaisep

This comment has been minimized.

Copy link
Owner Author

@blaisep blaisep commented Feb 2, 2020

is credentialid some kind of private or security credentials
which should not be publically available for everyone

I don't remember... I think that string is some kind of identifier that makes sense to the Jenkins server.

@sadokbani

This comment has been minimized.

Copy link

@sadokbani sadokbani commented Feb 12, 2020

how i can find my credentialsId of my repository !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment