Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to export credentials from one jenkins instance to another?

Tags:

I am using the credentials plugin in Jenkins to manage credentials for git and database access for my team's builds. I would like to copy the credentials from one jenkins instance to another, independent jenkins instance. How would I go about doing this?

like image 739
sakurashinken Avatar asked Jun 08 '15 08:06

sakurashinken


People also ask

How do I get my credentials from Jenkins?

To retrieve Jenkins credentials, you should import cloudbees credentials specific libraries. And use the lookupCredentials function to get all the credentials stored in Jenkins. Here is the full groovy script to list all the Jenkins credentials.

Where are credentials stored in Jenkins?

Encryption of Secrets and Credentials. Jenkins uses AES to encrypt and protect secrets, credentials, and their respective encryption keys. These encryption keys are stored in $JENKINS_HOME/secrets/ along with the master key used to protect said keys.

How do I unmask a password in Jenkins?

Go to the jenkins workspace and look inside the file. The token will be present in plain text there. Further easy way will be to print the base64 encoded value of the credential and then decode it.


2 Answers

UPDATE: TL;DR Follow the link provided below in a comment by Filip Stachowiak it is the easiest way to do it. In case it doesn't work for you go on reading.

Copying the $HUDSON_HOME/credentials.xml is not the solution because Jenkins encrypts paswords and these can't be decrypted by another instance unless both share a common key.

So, either you use the same encription keys in both Jenkins instances (Where's the encryption key stored in Jenkins? ) or what you can do is:

  1. Create the same user/password, you need to share, in the 2nd Jenkins instance so that a valid password is generated
  2. What is really important is that user ids in both credentials.xml are the same. For that (see the credentials.xml example below) for user: Jenkins the identifier <id>c4855f57-5107-4b69-97fd-298e56a9977d</id> must be the same in both credentials.xml

    <com.cloudbees.plugins.credentials.SystemCredentialsProvider plugin="[email protected]">   <domainCredentialsMap class="hudson.util.CopyOnWriteMap$Hash">     <entry>       <com.cloudbees.plugins.credentials.domains.Domain>         <specifications/>       </com.cloudbees.plugins.credentials.domains.Domain>       <java.util.concurrent.CopyOnWriteArrayList>                         <com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl>           <scope>GLOBAL</scope>           <id>c4855f57-5107-4b69-97fd-298e56a9977d</id>           <description>Para SVN</description>           <username>jenkins</username>           <password>J1ztA2vSXHbm60k5PjLl5jg70ZooSFKF+kRAo08UVts=               </password>                                 </com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl>       </java.util.concurrent.CopyOnWriteArrayList>     </entry>   </domainCredentialsMap> </com.cloudbees.plugins.credentials.SystemCredentialsProvider> 
like image 114
Pedro Avatar answered Sep 20 '22 08:09

Pedro


I was also facing the same problem. What worked for me is I copied the credentials.xml, config.xml and the secrets folder from existing jenkins to the new instance. After the restart of jenkins things worked fine.

like image 30
MS_22 Avatar answered Sep 21 '22 08:09

MS_22