Skip to content

Instantly share code, notes, and snippets.

@kpettijohn
Last active June 23, 2019 04:38
Show Gist options
  • Save kpettijohn/e294c50e29ca4e8a329e to your computer and use it in GitHub Desktop.
Save kpettijohn/e294c50e29ca4e8a329e to your computer and use it in GitHub Desktop.
Configure GitHub Pull Request Builder Jenkins plugin with Groovy
// ghprb 1.29.2
import java.lang.reflect.Field
import jenkins.model.*
import org.jenkinsci.plugins.ghprb.*
def descriptor = Jenkins.instance.getDescriptorByType(org.jenkinsci.plugins.ghprb.GhprbTrigger.DescriptorImpl.class)
Field auth = descriptor.class.getDeclaredField("githubAuth")
auth.setAccessible(true)
githubAuth = new ArrayList<GhprbGitHubAuth>(1)
githubAuth.add(new GhprbGitHubAuth("https://api.github.com", "aebe0886-5ead-47cd-9a13-18490b7a2831", "test1", "d1e9f1cb-c1e0-42f6-b3d9-6ccca25729ab", null))
githubAuth.add(new GhprbGitHubAuth("https://api.github.com", "3ebe0886-5ead-47cd-9a13-18490b7a2831", "test2", "31e9f1cb-c1e0-42f6-b3d9-6ccca25729ab", null))
auth.set(descriptor, githubAuth)
descriptor.save()
return
@grav
Copy link

grav commented Nov 21, 2017

See api here:
https://github.com/jenkinsci/ghprb-plugin/blob/master/src/main/java/org/jenkinsci/plugins/ghprb/GhprbGitHubAuth.java#L71

Order is:

String serverAPIUrl, 
String jenkinsUrl, 
String credentialsId, 
String description, 
String id,
Secret secret

If serverAPIUrl and id are left empty (""), they'll default to github api url and a random id respectively.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment