Skip to content

Instantly share code, notes, and snippets.

@hayderimran7
Last active February 15, 2021 17:22
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save hayderimran7/78421229af85ae90177b to your computer and use it in GitHub Desktop.
Save hayderimran7/78421229af85ae90177b to your computer and use it in GitHub Desktop.
So what is the 'credentials-id' parameter and how to use it correctly in jenkins-job-builder yaml file of your job?
It took me a while, after multiple knocks on all openstack/cloudbees/jenkins IRCs and googling around, all of them proved to be fruitless that I finally figure what the deal about this parameter all about?
before posting the exact details, i just have a little rant : WHY IS THIS NOT IN THE DOCS OF JENKINS JOB BUILDER (JJB ) ???
Jenkins job builder docs are pretty concise and dont go into much details,
but anyway:
=================================
what is credentials-id parameter?
=================================
so you are writing a yaml file for your job 'foo.yaml' and you need to use a git repo, lets say its in github,
now github private repos are snowflaky where you need to provide credentials to github in order to clone them. Following is step-by-step howto:
1. First add your jenkins credentials under global credentials i.e. add the ssh key that you generated for jenkins user (/var/lib/jenkins/.ssh)
2. Make sure, that your jenkins user can clone the private repo using this key. Meaning the public key of jenkins is added to the account of whoever has the private repo owned to.
3. Now comes the important part, you dont see any mention of 'id' afer you create your jenkins credentials, i.e. all you see is name of your credential and what key you added for it in keys.
SO the id is seen when you click on that specific credential you created in jenkins, see the url , the last field in the URL is the credential-id ..!!
yes , the 32-digit hexadecimal code is the credential id.
like my credential-id looks like this : '7b274a40-4533-4d2d-a37f-917d5b785e97'
Lets get over this once again, create a credential named "jenkins", add the key as mentioned above, now click on credentials and then click on "jenkins" .
you will see a url, after 'jenkins' , take note of that long token-ish hexadecimal id, thats your credential-id.
4. now in your job yaml file , under scm > git > credentials-id: write that id there, so when you update your job,
you will get correct credentials and can clone the private github repo..
i hope you guys find the solution here, too bad docs dont mention anything like that . ;)
cheers .
-------------------------------------------------------------------------------------------------------------------------
Copy link

ghost commented Jan 21, 2017

this is now shown in the credentials page

@vidhim
Copy link

vidhim commented Nov 17, 2017

can we checkout private git repo without setting these credentials and pass them as string in jenkins job

@premjitLourembam
Copy link

how i will use username and password instead of using credentialID

@SimplyKnownAsG
Copy link

thank you for this.

@ChinaShrimp
Copy link

thanks a lot for your nice explanation, it gives me very clear direction :)

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