snippetMinor
How to use stored certificate in Jenkins declarative pipeline?
Viewed 0 times
storedcertificatedeclarativejenkinshowusepipeline
Problem
I have a stored certificate in Jenkins, and I need to use it in a pipelinebuild job, but the problem is it appears the Pipeline can't use certificates:
trying to use:
results in:
How do I get around this and use that stored cert in a pipeline? There has to be a way otherwise why would storing certs as credentials even be possible.. would be useless to store something without ever being able to use it.
trying to use:
environment {
KEY = credentials('mycert')
}results in:
ERROR: No suitable binding handler could be found for type com.cloudbees.plugins.credentials.impl.CertificateCredentialsImpl. Supported types are StandardUsernamePasswordCredentials,FileCredentials,StringCredentials,SSHUserPrivateKey.How do I get around this and use that stored cert in a pipeline? There has to be a way otherwise why would storing certs as credentials even be possible.. would be useless to store something without ever being able to use it.
Solution
Some credential types cannot be bound directly in an environment section. From the docs :
If you need to set credentials in a Pipeline for anything other than secret text, usernames and passwords, or secret files - i.e SSH keys or certificates, then use Jenkins' Snippet Generator feature, which you can access through Jenkins' classic UI.
So the generator would give you something looking like this:
If you need to set credentials in a Pipeline for anything other than secret text, usernames and passwords, or secret files - i.e SSH keys or certificates, then use Jenkins' Snippet Generator feature, which you can access through Jenkins' classic UI.
So the generator would give you something looking like this:
withCredentials([certificate(aliasVariable: '', credentialsId: 'myCert', keystoreVariable: 'CERT', passwordVariable: '')]) {
// some block
}Code Snippets
withCredentials([certificate(aliasVariable: '', credentialsId: 'myCert', keystoreVariable: 'CERT', passwordVariable: '')]) {
// some block
}Context
StackExchange DevOps Q#8002, answer score: 2
Revisions (0)
No revisions yet.