Guest User

Untitled

a guest
May 26th, 2018
639
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. import jenkins.model.*
  2. import com.cloudbees.plugins.credentials.*
  3. import com.cloudbees.plugins.credentials.common.*
  4. import com.cloudbees.plugins.credentials.domains.*
  5. import com.cloudbees.plugins.credentials.impl.*
  6. import com.cloudbees.jenkins.plugins.sshcredentials.impl.*
  7. import hudson.plugins.sshslaves.*;
  8.  
  9. domain = Domain.global()
  10. store = Jenkins.instance.getExtensionList('com.cloudbees.plugins.credentials.SystemCredentialsProvider')[0].getStore()
  11.  
  12. credId = 'jenkinsgithub'
  13. username = 'jenkins'
  14. privateKeyStr = "-----BEGIN RSA PRIVATE KEY-----\nMIIJ..."
  15. privateKeySource = new BasicSSHUserPrivateKey.DirectEntryPrivateKeySource(privateKeyStr)
  16. description = "Jenkins GitHub SSH Credentials"
  17.  
  18. privateKey = new BasicSSHUserPrivateKey(
  19. CredentialsScope.GLOBAL,
  20. credId,
  21. username,
  22. privateKeySource,
  23. "",
  24. description
  25. )
  26.  
  27. store.addCredentials(domain, privateKey)
Add Comment
Please, Sign In to add comment