janinko / ghprb

github pull requests builder plugin for Jenkins
https://wiki.jenkins-ci.org/display/JENKINS/GitHub+pull+request+builder+plugin
MIT License
370 stars 20 forks source link

Ghprb cannot manage webhooks when credentials are configured using init.d scripts #468

Open brandon-fryslie opened 7 years ago

brandon-fryslie commented 7 years ago

I'm unable to get the ghprb plugin to properly manage my github webhooks when used with the Job DSL. After looking at the code, I believe this is an architectural issue with the plugin. I'll describe my setup and then I'll describe the problem more in-depth. Maybe someone can help me find a solution.

I'm running Jenkins 2.67, GHPRB 1.38.0 and Job DSL 1.63. I'm running Jenkins in docker with the Jenkins home directory stored on a persistent volume. We rebuild the docker image and redeploy once a week or more so we're on the newest version of everything most of the time. We configure Jenkins entirely using init.d scripts including all plugins and credentials.

When Jenkins comes up, it initializes itself, then the plugins, then any existing jobs in its data directory, then runs the init.d scripts. These init scripts configure the credentials and also create the seed job to run the Job DSL and configure/reconfigure any existing jobs.

When there are no existing jobs, the init scripts create the credentials first, and then the Job DSL runs which starts the GHPRB plugin. The plugin can then successfully create the webhooks.

However, if there are existing jobs, the GHPRB plugin starts before the init.d scripts run and the credentials are created, which causes the plugin to attempt to create the webhook using an anonymous credential. This fails causing an error.

I'm wondering if there is a way to have the plugin defer creating the webhook until after the init scripts have been processed?

Steps to reproduce:

  1. Install Jenkins & GHPRB plugin in a docker image w/ JENKINS_HOME mounted to a persistent volume
  2. Configure credentials and GHPRB plugin w/ init.d script
  3. Use Job DSL to create a job w/ GHPRB trigger that uses github webhooks
  4. Start container
  5. On the first startup, GHPRB will create the webhook when the DSL is processed (after init.d scripts)
  6. Kill & delete Jenkins container
  7. Start new container from image w/ volume mount
  8. GHPRB plugin is now started BEFORE init.d scripts, so it fails to manage the github webhooks properly

Please get in touch if there are any more questions. Thanks