<p>Some credential types cannot be bound directly in an environment section. <a href="https://jenkins.io/doc/book/pipeline/jenkinsfile/#handling-credentials" rel="nofollow noreferrer">From the docs</a> : </p>

<blockquote>
  <p>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.</p>
</blockquote>

<p>So the generator would give you something looking like this:</p>

<pre><code>withCredentials([certificate(aliasVariable: '', credentialsId: 'myCert', keystoreVariable: 'CERT', passwordVariable: '')]) {
    // some block
}
</code></pre>

CC BY-SA 4.0
2019-05-14T22:24:25.530Z
2019-05-14T22:24:25.530Z
plmaheu
<p>I usually set the credential NAME into an environment variable</p>

<pre><code>environment {
    CERT = 'mycert'
}
</code></pre>

<p>Then I can use that name where ever I need it</p>

<pre><code>withCredentials([usernamePassword(credentialsId: "${env.CERT}",
                                  passwordVariable: 'CERT_PASSWORD',
                                  usernameVariable: 'CERT_USER')]) {
    // Do things needing environment variables
}
</code></pre>

<p>or</p>

<pre><code>checkout(poll: false,
         scm: [
               $class: 'GitSCM',
               userRemoteConfigs: [[credentialsId: "${env.CERT}", 
                                   url: 'https://code.example.org/somerepo']]
               ])
</code></pre>

CC BY-SA 4.0
2019-05-03T16:24:31.103Z
2019-05-03T16:24:31.103Z
kdopen
<p>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:</p>

<p>trying to use:</p>

<pre><code>    environment {
        KEY = credentials('mycert')
    }
</code></pre>

<p>results in:</p>

<pre><code>ERROR: No suitable binding handler could be found for type com.cloudbees.plugins.credentials.impl.CertificateCredentialsImpl. Supported types are StandardUsernamePasswordCredentials,FileCredentials,StringCredentials,SSHUserPrivateKey.
</code></pre>

<p>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.</p>

<jenkins><jenkins-pipeline>
How to use stored certificate in Jenkins declarative pipeline?
Scott Shorkey
# How to use stored certificate in Jenkins declarative pipeline?

(Asked by: username_0 on 2019-05-02)

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:
    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.

**Tags:** jenkins, jenkins-pipeline


---

## 2 answers

### Answer by username_1 on 2019-05-14. Score: 2

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:
withCredentials([certificate(aliasVariable: '', credentialsId: 'myCert', keystoreVariable: 'CERT', passwordVariable: '')]) {
    // some block
}


---

### Answer by username_2 on 2019-05-03. Score: 1

I usually set the credential NAME into an environment variable
environment {
    CERT = 'mycert'
}

Then I can use that name where ever I need it
withCredentials([usernamePassword(credentialsId: "${env.CERT}",
                                  passwordVariable: 'CERT_PASSWORD',
                                  usernameVariable: 'CERT_USER')]) {
    // Do things needing environment variables
}

or
checkout(poll: false,
         scm: [
               $class: 'GitSCM',
               userRemoteConfigs: [[credentialsId: "${env.CERT}", 
                                   url: 'https://code.example.org/somerepo']]
               ])


---

