ghprb-plugin icon indicating copy to clipboard operation
ghprb-plugin copied to clipboard

Configuring Github deploy key as the credential

Open tzaeru opened this issue 4 years ago • 0 comments

Hi,

I've a repository with a few deploy keys created for it. These are meant to be used by CI.

Currently, I create the credentials like this:

import jenkins.model.*
import org.jenkinsci.plugins.ghprb.*
import hudson.util.Secret

[..]

  GhprbTrigger.DescriptorImpl descriptor = Jenkins.instance.getDescriptorByType(org.jenkinsci.plugins.ghprb.GhprbTrigger.DescriptorImpl.class)

  List<GhprbGitHubAuth> githubAuths = descriptor.getGithubAuth()

  String serverAPIUrl = 'https://api.github.com'
  String jenkinsUrl = '<our url>'
  String credentialsId = 'GHPRB credentials ID'
  String description = 'GHPRB'
  String id = 'GHPRB credentials ID'
  String secret = keyContent
  githubAuths.add(new GhprbGitHubAuth(serverAPIUrl, jenkinsUrl, credentialsId, description, id, Secret.fromString(keyContent)))

  descriptor.save()

keyContent is a SSH key retrieved from AWS secretsmanager.

This doesn't seem to work however - the requests hang for a long while until they fail.

I've a few questions.

  1. How might I configure a deploy key properly for GHPRB?
  2. Can I use BasicSSHUserPrivateKey from the SSH Credentials plugins or can I use credentials stored in that plugin, and if so, how?
  3. How do I make the credential I add above the default? Right now this just adds the credential to the end of the credentials for GHPRB. Each time I run this, it creates new credentials which is not what I want. Rather I just want to create a set of credentials once via code.

tzaeru avatar May 25 '20 14:05 tzaeru