Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Setup Jenkins Credentials
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()
priveteKey = new BasicSSHUserPrivateKey(
CredentialsScope.GLOBAL,
"jenkins-slave-key",
"root",
new BasicSSHUserPrivateKey.UsersPrivateKeySource(),
"",
""
)
usernameAndPassword = new UsernamePasswordCredentialsImpl(
CredentialsScope.GLOBAL,
"jenkins-slave-password", "Jenkis Slave with Password Configuration",
"root",
"jenkins"
)
store.addCredentials(domain, priveteKey)
store.addCredentials(domain, usernameAndPassword)
@chrisvire

This comment has been minimized.

Show comment Hide comment
@chrisvire

chrisvire Nov 9, 2015

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

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

@chrisvire

This comment has been minimized.

Show comment Hide comment
@chrisvire

chrisvire Nov 10, 2015

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

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

@chrisvire

This comment has been minimized.

Show comment Hide comment
@chrisvire

chrisvire Nov 24, 2015

I had to update my fork to correctly deal with DiskFileItem

I had to update my fork to correctly deal with DiskFileItem

@salmanpatel

This comment has been minimized.

Show comment Hide comment
@salmanpatel

salmanpatel Jul 11, 2017

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 ?

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 ?

@ihormudryy

This comment has been minimized.

Show comment Hide comment
@ihormudryy

ihormudryy Apr 19, 2018

Can you help to add AWS and Secret credentials?

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