Skip to content

Instantly share code, notes, and snippets.

@AdamSaleh
Created May 22, 2018 13:29
Show Gist options
  • Save AdamSaleh/c9cff0372d9362eb33b7bb5f47346fd2 to your computer and use it in GitHub Desktop.
Save AdamSaleh/c9cff0372d9362eb33b7bb5f47346fd2 to your computer and use it in GitHub Desktop.
import jenkins.model.*
import com.cloudbees.plugins.credentials.*
import com.cloudbees.plugins.credentials.common.*
import com.cloudbees.plugins.credentials.domains.*
import com.cloudbees.plugins.credentials.impl.*
import com.cloudbees.jenkins.plugins.sshcredentials.impl.*
import hudson.plugins.sshslaves.*;
domain = Domain.global()
store = Jenkins.instance.getExtensionList('com.cloudbees.plugins.credentials.SystemCredentialsProvider')[0].getStore()
credId = 'jenkinsgithub'
username = 'jenkins'
privateKeyStr = "-----BEGIN RSA PRIVATE KEY-----\nMIIJ..."
privateKeySource = new BasicSSHUserPrivateKey.DirectEntryPrivateKeySource(privateKeyStr)
description = "Jenkins GitHub SSH Credentials"
privateKey = new BasicSSHUserPrivateKey(
CredentialsScope.GLOBAL,
credId,
username,
privateKeySource,
"",
description
)
store.addCredentials(domain, privateKey)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment