The folder example will only work if the folder already has a FolderCredentialsProperty (e.g., because some credentials were defined from GUI side before). Newly created folders do not have that, and the example will fail.
In that case, you can create a new FolderCredentialsProperty - which can take a list of credentials as parameter:
--------
[...]
if(property) { println "Add credentials in global store" property.getStore().addCredentials(Domain.global(), c) } else { println "Initialize Folder Credentials store and add credentials in global store" property = new FolderCredentialsProperty([c]) folderAbs.addProperty(property) }
Thanks for the folder example. It works fine if used as init.groovy.d script. However it doesn't seems to work if used in a jenkinsfile or a groovy dsl file.
How to add a credential domain via groovy ? I want to add a credential domain on a specific folder (Folder -> Credential -> Add domain) and then inside this domain add a credential.
This script puts the created credential into the 'global' domain. Is there any way to do this for a specific folder domain?
i.e. I have a folder called 'build-jobs' and it has a credentials domain called 'build-jobs-credentials' and I only want to add credentials under that domain. Is is possible with Groovy?
Your blog is quite informative, but I see that these are the ways if you want to add credentials globally or for a folder, what about the project/job then? Will you please mention the script for how can we generate credentials that are specific to job/project. Thanks in advance.
Comments
9 comments
The folder example will only work if the folder already has a
FolderCredentialsProperty
(e.g., because some credentials were defined from GUI side before). Newly created folders do not have that, and the example will fail.How to proceed in that case?
In that case, you can create a new FolderCredentialsProperty - which can take a list of credentials as parameter:
--------
[...]
if(property) {
println "Add credentials in global store"
property.getStore().addCredentials(Domain.global(), c)
} else {
println "Initialize Folder Credentials store and add credentials in global store"
property = new FolderCredentialsProperty([c])
folderAbs.addProperty(property)
}
--------
See source code of FolderCredentialsProvider.FolderCredentialsProperty
Hi,
Thanks for the folder example. It works fine if used as init.groovy.d script. However it doesn't seems to work if used in a jenkinsfile or a groovy dsl file.
following import fails
Any hints how to use it from a groovy dsl script ?
Hi Marc,
You have the (CloudBees) Folder plugin installed ? In which version ?
Hi Arnaud,
I'm running jenkins LTS 2.32.2 with the folder plugin version 5.17.
Cheers
How to add a credential domain via groovy ? I want to add a credential domain on a specific folder (Folder -> Credential -> Add domain) and then inside this domain add a credential.
Hi!
I have a question about this script.
This script puts the created credential into the 'global' domain. Is there any way to do this for a specific folder domain?
i.e. I have a folder called 'build-jobs' and it has a credentials domain called 'build-jobs-credentials' and I only want to add credentials under that domain. Is is possible with Groovy?
Thanks!
Hi
Instead of randomly generated "ID", how can I have a fixed though this script?
Something like "userid_prod_usertoken_github-enterprise-prod" #36 char length
Thanks!
Hi,
Your blog is quite informative, but I see that these are the ways if you want to add credentials globally or for a folder, what about the project/job then? Will you please mention the script for how can we generate credentials that are specific to job/project.
Thanks in advance.
Please sign in to leave a comment.