How to export credentials from one jenkins instance to another?

我的梦境 提交于 2019-12-29 03:31:05

问题


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?


回答1:


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="credentials@1.22">
      <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>
    



回答2:


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.




回答3:


This is what worked for me.

Create a job in Jenkins that takes the credentials and writes them to output. If Jenkins replaces the password in the output with ****, just obfuscate it first (add a space between each character, reverse the characters, base64 encode it, etc.)

I used a Powershell job to base64 encode it:

[convert]::ToBase64String([text.encoding]::Default.GetBytes($mysecret))

And then used Powershell to convert the base64 string back to a regular string:

[text.encoding]::Default.GetString([convert]::FromBase64String("bXlzZWNyZXQ="))



回答4:


Did you try to copy the $JENKINS_HOME/users folder and the $JENKINS_HOME/credentials.xml file to the other Jenkins instance?



来源:https://stackoverflow.com/questions/30704856/how-to-export-credentials-from-one-jenkins-instance-to-another

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!