w2bro
w2bro

Reputation: 1016

GitHub Organization Repo + Jenkins (GitHub Plugin) integration

I have an organization on GitHub with private repositories. I also have Jenkins set up running on port 8080 on a server, with the GitHub plugin installed. I've created an account on GitHub for my jenkins user, which resides in the owners group.

I'm trying to trigger a job on jenkins when a change is pushed to my development branch (or master branch, neither seem to be working).

When I look at the GitHub Hook Logs in Jenkins, it says that Polling has not run yet. When I go to "Manage Jenkins", the GitHub plugin says my account is Verified when I test it.

Any insight on how to configure this? I have multiple repositories I'd like to work with, so deploy keys don't seem like the solution to me.

Upvotes: 6

Views: 13315

Answers (3)

VonC
VonC

Reputation: 1323045

Update:

As Craig Ringer mentions in his answer, you can select Grant READ permissions for /github-webhook in "Configure Jenkins" under the GitHub plugin settings, allowing the webhook to be called without authentication.

Another update: Webhooks are now (Dec. 2014) available for organization: see WebHooks API for orgs.


Note: the issue 4 of the hudson-github-plugin was about:

Last GitHub Push

Polling has not run yet.

And the conclusion was:

Nevermind, the only missing piece was a permission checkbox for the github user which ain't documented anywhere on the internet.

So is this a permission issue regarding your Jenkins users?

The article "Set up Jenkins-CI on Ubuntu for painless Rails3 app CI testing" includes the following process:

To restrict the CI system and give access to your Team members to use or see the build logs, first you’ve to create an account.

  • Go to Manage Jenkins > Configure System,
  • Check the Enable Security checkbox
  • Under Security Realm, choose Jenkins's own user database
  • Check the Allow users to sign up checkbox
  • Under Authorization, choose Project-based Matrix Authorization Strategy
  • Add first user with the name admin and another with GitHub (Note: the username for Admin access has to be admin) For GitHub named user, just choose the Overall Read only permission. We’ll use this user later with the GitHub hook.

Note: The admin and GitHub user that we’ve added in the above step does not create the User. Then you’ve to create a real user with that same name. Ya, I know, its a bit weird with Jenkins UI.

Go to Manage Jenkins > Manage Users > Create User. Create both admin and GitHub users.

Hooking with the Github web-hooks

Now to run the build automagically when new commit or branch gets pushed onto Github, we have to setup the repository.

Got to the hooks page for your repository. e.g.

github.com/<username>/<project_name>/admin/hooks

Under AVAILABLE SERVICE HOOKS > Post-Receive URLs, add github:[email protected]/github-webhook/.

The github:github is the user that we’d created earlier.

Then we have to verify Jenkins with Github. Go to Manage Jenkins > Configure System and under GitHub Web Hook, add your Github username and password and click the Test Credential button to authorize once with Github.

Upvotes: 8

Craig Ringer
Craig Ringer

Reputation: 324265

It looks like the accepted answer is no longer necessary with the current version of the GitHub plugin. You can instead check Grant READ permissions for /github-webhook in "Configure Jenkins" under the GitHub plugin settings, allowing the webhook to be called without authentication.

As explained in the help on this option that's quite safe, and frankly no worse than having a user named "github" with password "github" anyway.

Upvotes: 2

iltempo
iltempo

Reputation: 16012

There are two ways to achieve automatic builds on Jenkins. What you choose depends on whether GitHub can call the Jenkins server URL you provide. This may not be the case if you are running Jenkins behind a firewall.

  1. If GitHub can reach that URL you can set up the service hook on your repo there.
  2. If not you can set up Jenkins to poll periodically.

You may set up both, but one solution is enough to get it working. I would always go for the first if feasible as it saves resources CPU and traffic wise.

Either way you need the GitHub plugin for Jenkins.

Hope that helps a bit.

Upvotes: 0

Related Questions