我发现了如何使用基于groovy的Jenkins API存储用户名/密码或SSH用户名/ PrivateKey。

https://gist.github.com/iocanel/9de5c976cc0bd5011653

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)


可以存储更多种类的凭证。我该怎么办:


秘密档案
秘密文字

最佳答案

经过研究后,我发现纯凭证插件实现了Secret Text和Secret File凭证。我在上面列出了要点,并添加了这两种类型的代码(请参阅要点,以了解所需的导入内容)。

https://gist.github.com/chrisvire/383a2c7b7cfb3f55df6a

secretText = new StringCredentialsImpl(
CredentialsScope.GLOBAL,
"secret-text",
"Secret Text Description",
Secret.fromString("some secret text goes here"))

file = new File("/path/to/some/file")
noFileItem = [ getName: { return "" } ] as FileItem
FileCredentailsImpl can take a file from a do
secretFile = new FileCredentialsImpl(
CredentialsScope.GLOBAL,
"secret-file",
"Secret File Description"
noFileItem, // Don't use FileItem
file.getName(),
file.text)

store.addCredentials(domain, secretText)
store.addCredentials(domain, secretFile)

关于groovy - 如何使用Groovy存储 secret 文本或文件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33613868/

10-16 06:52