Open valter-silva-au opened 7 years ago
+1
+1
Workaround for now, to remove the credentials during each chef run and then recreate it:
jenkins_script 'hack around issue 591' do
command <<-EOH
import jenkins.model.*
import com.cloudbees.plugins.credentials.*;
import com.cloudbees.plugins.credentials.*
import com.cloudbees.plugins.credentials.common.*
import com.cloudbees.plugins.credentials.domains.*;
global_domain = com.cloudbees.plugins.credentials.domains.Domain.global()
credentials_store =
Jenkins.instance.getExtensionList(
'com.cloudbees.plugins.credentials.SystemCredentialsProvider'
)[0].getStore()
id_matcher = CredentialsMatchers.withId("REPLACE_ME_WITH_CREDENTIAL_ID")
available_credentials =
CredentialsProvider.lookupCredentials(
StandardUsernameCredentials.class,
Jenkins.instance,
hudson.security.ACL.SYSTEM,
new SchemeRequirement("ssh")
)
existing_credentials =
CredentialsMatchers.firstOrNull(
available_credentials,
id_matcher
)
if(existing_credentials != null) {
credentials_store.removeCredentials(
global_domain,
existing_credentials
)
}
EOH
end
any updates on this bug?
@Poohblah https://github.com/chef-cookbooks/jenkins/pull/597 works fine to me as a workaround
I meant updates from the project maintainers. I would really like to see #597 merged.
I've got what I believe to be a better workaround. Rather than delete and re-create the credentials every time, check to see if credentials.xml
contains the credentials:
jenkins_private_key_credentials 'mycreds' do
id 'mycreds'
private_key key
not_if do
credentials_file = '/var/lib/jenkins/credentials.xml'
matcher = '<description>Credentials for mycreds - created by Chef</description>'
re = /#{Regexp.quote matcher}/
File.exist?(credentials_file) && File.readlines(credentials_file).grep(re).any?
end
end
Cookbook version
5.0.0
Chef-client version
12.19.36
Platform Details
Ubuntu 16.04
Scenario:
Use resource
jenkins_private_key_credentials
.Steps to Reproduce:
Expected Result:
Create credential with the provided private key.
Actual Result:
If I remove the credentials via Jenkins web interface and try to converge, it works, but if I try to converge again, with the credential already created, it doesn't. Am I missing something ?
Thank you very much!