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

Unable to create folder credentials for plain-credentials-plugin

    Details

    • Similar Issues:

      Description

      Trying to create folder using job DSL but there is no option for credentials from plain-credentials-plugin - FileCredential and StringCredentials. Only credentials from credentials plugin are available.

        Attachments

          Activity

          Hide
          rittneje Jesse Rittner added a comment -

          I was able to work around this bug using the configure option for string creds.

           

          properties {
            folderCredentialsProperty {
              domainCredentials {
                 domainCredentials {
                  domain {
                    name('')
                    description('')
                  }
                }
              }   
            }
          }
          configure { folder ->
               def configNode = folder / 'properties''com.cloudbees.hudson.plugins.folder.properties.FolderCredentialsProvider_-FolderCredentialsProperty''domainCredentialsMap' / 'entry' / 'java.util.concurrent.CopyOnWriteArrayList'
             configNode << 'org.jenkinsci.plugins.plaincredentials.impl.StringCredentialsImpl'(plugin: 'plain-credentials@1.5') {
               id('secret-id')
               description('secret desc')
               secret(hudson.util.Secret.fromString('secret').getEncryptedValue())
             }
          }
          

          Unfortunately, I still cannot get file creds to work properly. It requires using com.cloudbees.plugins.credentials.SecretBytes, but attempting to do so gives all sorts of bizarre errors, like unable to resolve class com.cloudbees.plugins.credentials.SecretBytes or No such property: cloudbees for class: java.lang.String.

           

          Show
          rittneje Jesse Rittner added a comment - I was able to work around this bug using the configure  option for string creds.   properties { folderCredentialsProperty { domainCredentials { domainCredentials { domain { name('') description('') } } }   } } configure { folder ->      def configNode = folder / 'properties' /  'com.cloudbees.hudson.plugins.folder.properties.FolderCredentialsProvider_-FolderCredentialsProperty' /  'domainCredentialsMap' / 'entry' / 'java.util.concurrent.CopyOnWriteArrayList'   configNode << 'org.jenkinsci.plugins.plaincredentials.impl.StringCredentialsImpl' (plugin: 'plain-credentials@1.5' ) { id( 'secret-id' ) description( 'secret desc' ) secret(hudson.util.Secret.fromString( 'secret' ).getEncryptedValue())   } } Unfortunately, I still cannot get file creds to work properly. It requires using com.cloudbees.plugins.credentials.SecretBytes, but attempting to do so gives all sorts of bizarre errors, like unable to resolve class com.cloudbees.plugins.credentials.SecretBytes or No such property: cloudbees for class: java.lang.String .  
          Hide
          jswager1 Jason Swager added a comment - - edited

          Jesse Rittner - perhaps this will help. Your original example helped me get much further; I couldn't have figured out the secret file stuff without your example.

          properties {
            folderCredentialsProperty {
              domainCredentials {
                 domainCredentials {
                  domain {
                    name('')
                    description('')
                  }
                }
              }   
            }
          }
          configure { folder ->
               def configNode = folder / 'properties''com.cloudbees.hudson.plugins.folder.properties.FolderCredentialsProvider_-FolderCredentialsProperty''domainCredentialsMap' / 'entry' / 'java.util.concurrent.CopyOnWriteArrayList'
            configNode << 'org.jenkinsci.plugins.plaincredentials.impl.FileCredentialsImpl' {
              id('secret-file-id')
              description('secret file desc')
              fileName('test.txt')
              secretBytes(com.cloudbees.plugins.credentials.SecretBytes.fromBytes('''This is a multiline file
          Line two
          final line'''.getBytes()).toString())
            }
          }
          

          This example won't work with a binary file.  If that was necessary, you could generate a BASE64 encode of the binary file, put that in place of the string and do a decodeBase64() on it to get the bytes.

          Show
          jswager1 Jason Swager added a comment - - edited Jesse Rittner - perhaps this will help. Your original example helped me get much further; I couldn't have figured out the secret file stuff without your example. properties { folderCredentialsProperty { domainCredentials { domainCredentials { domain { name('') description('') } } }   } } configure { folder ->      def configNode = folder / 'properties' /  'com.cloudbees.hudson.plugins.folder.properties.FolderCredentialsProvider_-FolderCredentialsProperty' /  'domainCredentialsMap' / 'entry' / 'java.util.concurrent.CopyOnWriteArrayList' configNode << 'org.jenkinsci.plugins.plaincredentials.impl.FileCredentialsImpl' { id( 'secret-file-id' ) description( 'secret file desc' ) fileName( 'test.txt' ) secretBytes(com.cloudbees.plugins.credentials.SecretBytes.fromBytes('''This is a multiline file Line two final line'''.getBytes()).toString()) } } This example won't work with a binary file.  If that was necessary, you could generate a BASE64 encode of the binary file, put that in place of the string and do a decodeBase64() on it to get the bytes.
          Hide
          rittneje Jesse Rittner added a comment -

          Thanks, but unfortunately that still gives those weird error messages I posted.

          Also, just FYI you should also set scope('GLOBAL') for your credentials. Otherwise, your config might be corrupted.

           

          Show
          rittneje Jesse Rittner added a comment - Thanks, but unfortunately that still gives those weird error messages I posted. Also, just FYI you should also set scope('GLOBAL') for your credentials. Otherwise, your config might be corrupted.  

            People

            • Assignee:
              daspilker Daniel Spilker
              Reporter:
              mkovarik Michal Kovarik
            • Votes:
              2 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated: