Skip to content

Instantly share code, notes, and snippets.

@dragolabs
Last active March 6, 2020 13:42
Show Gist options
  • Select an option

  • Save dragolabs/b5de20e55b79a7e5e16685d58c5d01cb to your computer and use it in GitHub Desktop.

Select an option

Save dragolabs/b5de20e55b79a7e5e16685d58c5d01cb 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.jenkins.plugins.sshcredentials.impl.*
import hudson.plugins.sshslaves.*;
global_domain = Domain.global()
credentials_store =
Jenkins.instance.getExtensionList(
'com.cloudbees.plugins.credentials.SystemCredentialsProvider'
)[0].getStore()
// Use ''' key ''' if multiline and 'key\nkey\nkey' if one line
private_key = '[...]'
credentials = new BasicSSHUserPrivateKey(
CredentialsScope.GLOBAL,
// Credentional ID
null,
// Username
'jenkins',
// Private key
new BasicSSHUserPrivateKey.DirectEntryPrivateKeySource(private_key),
// Passphrase
'jenkins_key_passphrase',
// Description
''
)
credentials_store.addCredentials(global_domain, credentials)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment