[JIRA] (JENKINS-57435) Cannot configure SSH credentials via Job DSL

10 views
Skip to first unread message

tom@bibbu.net (JIRA)

unread,
May 13, 2019, 10:19:02 AM5/13/19
to jenkinsc...@googlegroups.com
Tom Wieczorek created an issue
 
Jenkins / Bug JENKINS-57435
Cannot configure SSH credentials via Job DSL
Issue Type: Bug Bug
Assignee: Daniel Spilker
Components: job-dsl-plugin
Created: 2019-05-13 14:18
Environment: Jenkins ver. 2.164.3
job-dsl 1.74
ssh-credentials 1.16
Priority: Major Major
Reporter: Tom Wieczorek

Version 1.16 of the SSH Credentials plugin changed the plain SSH private key from String to a hudson.util.Secret.

This leads to the situation that Job DSL cannot be used to configure SSH credentials any longer.

This snippet works when using SSH Credentials plugin 1.15:

folder('foo') {
  properties {
    folderCredentialsProperty {
      domainCredentials {
        domainCredentials {
          domain {
            name(null)
            description(null)
          }
          credentials {
            basicSSHUserPrivateKey {
              scope('GLOBAL')
              id('my-ssh')
              description('My SSH Credentials')
              username('me')
              passphrase('')
              privateKeySource {
                directEntryPrivateKeySource {
                  privateKey('SSH-PRIVATE-KEY-HERE')
                }
              }
            }
          }
        }
      }
    }
  }
}

But with SSH Credentials version 1.16, the privateKeySource directive shows as empty in the Job DSL's API browser.

Maybe there's a way to also support hudson.util.Secret in Job DSL (by simply wrapping Strings into Secret.fromString(...))?

Add Comment Add Comment
 
This message was sent by Atlassian Jira (v7.11.2#711002-sha1:fdc329d)

mail@daniel-spilker.com (JIRA)

unread,
Jun 11, 2019, 4:49:01 AM6/11/19
to jenkinsc...@googlegroups.com
Daniel Spilker updated an issue
Change By: Daniel Spilker
Component/s: ssh-credentials-plugin

mail@daniel-spilker.com (JIRA)

unread,
Jun 11, 2019, 4:50:02 AM6/11/19
to jenkinsc...@googlegroups.com
Daniel Spilker assigned an issue to Unassigned
Change By: Daniel Spilker
Assignee: Daniel Spilker

tom@bibbu.net (JIRA)

unread,
Sep 5, 2019, 10:53:04 AM9/5/19
to jenkinsc...@googlegroups.com
Tom Wieczorek commented on Bug JENKINS-57435
 
Re: Cannot configure SSH credentials via Job DSL

I opened PR #1202 that allows the usage of hudson.util.Secret as an input parameter, so that the following snippet works:

folder('foo') {
  properties {
    folderCredentialsProperty {
      domainCredentials {
        domainCredentials {
          domain {
            name(null)
            description(null)
          }
          credentials {
            basicSSHUserPrivateKey {
              scope('GLOBAL')
              id('my-ssh')
              description('My SSH Credentials')
              username('me'
)
              passphrase('')
              privateKeySource {
                directEntryPrivateKeySource {
                  privateKey(hudson.util.Secret.fromString('SSH-PRIVATE-KEY-HERE'))
                }
              }
            }
          }
        }
      }
    }
  }
}

renzo@crisostomo.me (JIRA)

unread,
Oct 18, 2019, 9:09:09 AM10/18/19
to jenkinsc...@googlegroups.com

If you're wondering how to do this with configure blocks, it's something like this:

configNode << 'com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey' {
    id("test_ssh_credentials")
    description("")
    username("test_ssh_credentials")
    privateKeySource(class:"com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey\$DirectEntryPrivateKeySource") {
        privateKey("""YOUR_PRIVATE_KEY_HERE""")
    }
}
This message was sent by Atlassian Jira (v7.13.6#713006-sha1:cc4451f)
Atlassian logo

renzo@crisostomo.me (JIRA)

unread,
Oct 18, 2019, 9:11:05 AM10/18/19
to jenkinsc...@googlegroups.com
Renzo Crisóstomo edited a comment on Bug JENKINS-57435
If you're wondering how to do this with configure blocks, it's something like this:


{code:java}
folder('example') {

    properties {
        folderCredentialsProperty {
            domainCredentials {
                domainCredentials {
                    domain {
                     name("")
                     description("")
                    }
                }
            }
        }
    }
    configure {
        def
configNode = it / 'properties' / 'com.cloudbees.hudson.plugins.folder.properties.FolderCredentialsProvider_-FolderCredentialsProperty' / 'domainCredentialsMap' / 'entry' / 'java.util.concurrent.CopyOnWriteArrayList'
        configNode
<< 'com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey' {

    id("test_ssh_credentials")
    description("")
    username("test_ssh_credentials")
    privateKeySource(class:"com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey\$DirectEntryPrivateKeySource") {
        privateKey("""YOUR_PRIVATE_KEY_HERE""")
    }
}
    }
}
{code}

rene.scheibe@gmail.com (JIRA)

unread,
Nov 4, 2019, 5:36:02 PM11/4/19
to jenkinsc...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages