Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-44588

pipeline declarative 'parameters' DSL should support credential parameter

XMLWordPrintable

      When creating release automation for blueocean, I wanted user to select their user store credentials as build input parameter. 

      I can do it using pipeline script:

       

      [$class: 'CredentialsParameterDefinition', credentialType: 'com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl', defaultValue: '', description: '', name: 'GITHUB_CREDENTIALS', required: true]
      

       

      I can't use declarative pipeline as it only supports string and boolean, there is no support for credentials parameter.

      abayer tells me its because there is no symbol on descriptor of https://github.com/jenkinsci/credentials-plugin/blob/master/src/main/java/com/cloudbees/plugins/credentials/CredentialsParameterDefinition.java.

      I also tried using string parameter with declarative where user types in their user store credential id but then declarative 'credentials' DSL failed to find it. Below is sample script where 'my-user-cred' is credential id created in user credentials store.

       

      pipeline{
          agent any
          environment { 
              USER_CRED = credentials('my-user-cred') 
          }
          stages {
              stage('Example') {
                  steps {
                      sh 'echo ${USER_CRED}'
                  }
              }
          }
      }
      

       

       It fails with:

      org.jenkinsci.plugins.credentialsbinding.impl.CredentialNotFoundException: my-user-cred
      	at org.jenkinsci.plugins.pipeline.modeldefinition.model.CredentialsBindingHandler.forId(CredentialsBindingHandler.java:121)
      	at org.jenkinsci.plugins.pipeline.modeldefinition.model.CredentialsBindingHandler$forId.call(Unknown Source)
      	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
      	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
      	at com.cloudbees.groovy.cps.sandbox.DefaultInvoker.methodCall(DefaultInvoker.java:18)
      	at 
      

      Probably these are two different issues but relates to declarative and credentials so thought will list them here.

       

       

       

            abayer Andrew Bayer
            vivek Vivek Pandey
            Votes:
            1 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: