Skip to content

Instantly share code, notes, and snippets.

Created September 1, 2015 09:12
Show Gist options
  • Save iocanel/9de5c976cc0bd5011653 to your computer and use it in GitHub Desktop.
Save iocanel/9de5c976cc0bd5011653 to your computer and use it in GitHub Desktop.
Setup Jenkins Credentials
import jenkins.model.*
import com.cloudbees.plugins.credentials.*
import com.cloudbees.plugins.credentials.common.*
import com.cloudbees.plugins.credentials.impl.*
import com.cloudbees.jenkins.plugins.sshcredentials.impl.*
import hudson.plugins.sshslaves.*;
domain =
store = Jenkins.instance.getExtensionList('com.cloudbees.plugins.credentials.SystemCredentialsProvider')[0].getStore()
priveteKey = new BasicSSHUserPrivateKey(
new BasicSSHUserPrivateKey.UsersPrivateKeySource(),
usernameAndPassword = new UsernamePasswordCredentialsImpl(
"jenkins-slave-password", "Jenkis Slave with Password Configuration",
store.addCredentials(domain, priveteKey)
store.addCredentials(domain, usernameAndPassword)
Copy link

Do you know how to do "secret file" or "secret text"? These are additional kinds of credentials that can be stored in Jenkins.

Copy link

I found a solution to secret file and secret text. I have forked the gist and updated my fork.

Copy link

I had to update my fork to correctly deal with DiskFileItem

Copy link

I am able to run this script when invoked using "Execute System Groovy Script" but not with "Process Job DSL" in one machine, while it runs with both in some machines. Can somebody help with the problem ?

Copy link

Can you help to add AWS and Secret credentials?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment