Skip to content

Instantly share code, notes, and snippets.

@grawert
Created March 28, 2016 06:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grawert/6a647e32dc56acf4a165 to your computer and use it in GitHub Desktop.
Save grawert/6a647e32dc56acf4a165 to your computer and use it in GitHub Desktop.
Add direct SSH credentials to Jenkins
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.*
credentials = new BasicSSHUserPrivateKey(
CredentialsScope.GLOBAL,
"",
"username_HERE",
new BasicSSHUserPrivateKey.DirectEntryPrivateKeySource(
"-----BEGIN RSA PRIVATE KEY-----\/-----END RSA PRIVATE KEY-----"
),
"",
"Description HERE"
)
store = Jenkins.instance.getExtensionList('com.cloudbees.plugins.credentials.SystemCredentialsProvider')[0].getStore()
store.addCredentials(Domain.global(), credentials)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment