Last active
March 6, 2020 13:42
-
-
Save dragolabs/b5de20e55b79a7e5e16685d58c5d01cb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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