Instantly share code, notes, and snippets.

Embed
What would you like to do?
Jenkins setup

I just had to set up Jenkins to use GitHub. My notes (to myself, mostly):

Detailed Instructions

For setting up Jenkins to build GitHub projects. This assumes some ability to manage Jenkins, use the command line, set up a utility LDAP account, etc. Please share or improve this Gist as needed.

Install Jenkins Plugins

Make a Utility Account in the GitHub (optional)

  • This would keep your identity separate from your Jenkins server
  • Helpful if Jenkins runs under a different user

On the Jenkins server (optional)

  • If Jenkins does run as different user, set this up on your server
  • Set git user.name and user.email global config options.
  • 'git config --global user.email JENKINS_USERNAME@WHATEVER_HOSTNAME'
  • 'git config --global user.name JENKINS_USERNAME'
  • This should match the GitHub utility account username and email address

Generate rsa key pair on your Jenkins server

Update the GitHub Account for Jenkins

  • Register utility user with git.corp.adobe.com
  • Log in the utility account
  • Go to Account Settings > SSH Keys
  • Add the contents of the public key from your server

Configure Jenkins

  • Make sure the Manage Jenkins > Configure System has the right path to git
  • Set the global git user.name and user.email to match your global config options
  • Configure GitHub Web Hook to Manually manage hook urls
  • Click the (?) icon next to the manual option and copy the hook URL you see there
  • Optionally set the service account email as the Jenkins sender email address

Configure Github Project

  • Log into Github as the owner or collaborator of a repo
  • Click the Admin button for that repo
  • Select 'Service Hooks' in the left column
  • Select 'Jenkins (Github plugin)' in the Available Service Hooks column
  • Add the service hook URL for your server eg http://yourjenkinsmachine.com:8080/github-webhook/ you might find the URL in the GitHub Web Hook > Manual setting (?) help text
  • Check the 'Active' checkbox

Create a Jenkins job

  • In the general options, add the URL to the github project eg 'http://github.com/tehfoo/build-test/'
  • Under Source Code Management, select Git
  • For the repository URL, enter the SSH URL for your project this is found by toggling the HTTP/SSH button to the right of the URL field on the repo home page in GitHub eg 'git@github.com:ixab/build-test.git'
  • Under Build Triggers, check the "Build when a change is pushed to GitHub"
  • Add other build task (running Grunt, or Ant, or scary Maven stuff, or whatever)

Enjoy!

@dfong

This comment has been minimized.

Show comment
Hide comment
@dfong

dfong Aug 27, 2013

thanks for writing these notes. the process is more arduous than i would have expected.

i assume the references to git.corp.adobe.com should be "your github server"?

"click the admin button for that repo" - do you mean the "settings" button?

after clicking the "active" checkbox, should there be another step "click the save button"?

dfong commented Aug 27, 2013

thanks for writing these notes. the process is more arduous than i would have expected.

i assume the references to git.corp.adobe.com should be "your github server"?

"click the admin button for that repo" - do you mean the "settings" button?

after clicking the "active" checkbox, should there be another step "click the save button"?

@RajatBanerjee

This comment has been minimized.

Show comment
Hide comment
@RajatBanerjee

RajatBanerjee Feb 19, 2014

just made my day!

RajatBanerjee commented Feb 19, 2014

just made my day!

@iamlittle

This comment has been minimized.

Show comment
Hide comment
@iamlittle

iamlittle Jun 9, 2014

Saved my bacon!

iamlittle commented Jun 9, 2014

Saved my bacon!

@parteekkumar

This comment has been minimized.

Show comment
Hide comment
@parteekkumar

parteekkumar Jul 8, 2014

Please let me know why I am not getting option to pass "github" url in "Source Code Management" while creating Job

parteekkumar commented Jul 8, 2014

Please let me know why I am not getting option to pass "github" url in "Source Code Management" while creating Job

@hyao

This comment has been minimized.

Show comment
Hide comment
@hyao

hyao commented Sep 12, 2014

A similar (but simpler) doc here with screenshots:
http://thepracticalsysadmin.com/setting-up-a-github-webhook-in-jenkins/

@ddilley

This comment has been minimized.

Show comment
Hide comment
@ddilley

ddilley Dec 12, 2014

In reference to "Make a Utility Account in the GitHub": Is this referring to registering a github account as you would normally? I also want to re-ask dfong's unanswered question 'i assume the references to git.corp.adobe.com should be "your github server"?'

ddilley commented Dec 12, 2014

In reference to "Make a Utility Account in the GitHub": Is this referring to registering a github account as you would normally? I also want to re-ask dfong's unanswered question 'i assume the references to git.corp.adobe.com should be "your github server"?'

@dapacheco

This comment has been minimized.

Show comment
Hide comment
@dapacheco

dapacheco Oct 7, 2015

Thanks for the steps. I was able to use a passphrase by configuring it in the global credentials section of Jenkins (using version 1.631)

dapacheco commented Oct 7, 2015

Thanks for the steps. I was able to use a passphrase by configuring it in the global credentials section of Jenkins (using version 1.631)

@svigne1

This comment has been minimized.

Show comment
Hide comment
@svigne1

svigne1 May 2, 2016

Thank You so much for the post!

svigne1 commented May 2, 2016

Thank You so much for the post!

@ghost

This comment has been minimized.

Show comment
Hide comment
@ghost

ghost May 6, 2016

Thanks for this post! 👍

ghost commented May 6, 2016

Thanks for this post! 👍

@billkgeorge

This comment has been minimized.

Show comment
Hide comment
@billkgeorge

billkgeorge Jun 6, 2016

Thank you Yanesh.

billkgeorge commented Jun 6, 2016

Thank you Yanesh.

@ghost

This comment has been minimized.

Show comment
Hide comment
@ghost

ghost Jul 7, 2016

Thank you Yanesh! 👍

ghost commented Jul 7, 2016

Thank you Yanesh! 👍

@dit-j

This comment has been minimized.

Show comment
Hide comment
@dit-j

dit-j Sep 4, 2016

Make a Utility Account in the GitHub (optional).
ehm... what is this? What is Utility Account in the Github???

dit-j commented Sep 4, 2016

Make a Utility Account in the GitHub (optional).
ehm... what is this? What is Utility Account in the Github???

@MithPallakki

This comment has been minimized.

Show comment
Hide comment
@MithPallakki

MithPallakki Dec 14, 2016

Hi,

When I provide the Repository URL in the Source Code Management I am facing "Failed to connect to repository : Error performing command: git.exe ls-remote -h https://*******.git HEAD" issue.??
Can anyone help me on this.

MithPallakki commented Dec 14, 2016

Hi,

When I provide the Repository URL in the Source Code Management I am facing "Failed to connect to repository : Error performing command: git.exe ls-remote -h https://*******.git HEAD" issue.??
Can anyone help me on this.

@sathizzh

This comment has been minimized.

Show comment
Hide comment
@sathizzh

sathizzh Dec 22, 2016

what is JENKINS_USERNAME@WHATEVER_HOSTNAME can you give me a example

sathizzh commented Dec 22, 2016

what is JENKINS_USERNAME@WHATEVER_HOSTNAME can you give me a example

@srinivasaraokonidena

This comment has been minimized.

Show comment
Hide comment
@srinivasaraokonidena

srinivasaraokonidena Jan 5, 2017

@MithPallakki you just give git.exe c/program files/git/bin/git (which will be at place where git is installed in your local machine) at git global configuration

srinivasaraokonidena commented Jan 5, 2017

@MithPallakki you just give git.exe c/program files/git/bin/git (which will be at place where git is installed in your local machine) at git global configuration

@srinivasaraokonidena

This comment has been minimized.

Show comment
Hide comment
@srinivasaraokonidena

srinivasaraokonidena Jan 5, 2017

can anybody tell me how can we transfer required build artifact from nexus repository to higher environments using Jenkins build pipeline plugin and what is the use of parametrized trigger plugin in this process

srinivasaraokonidena commented Jan 5, 2017

can anybody tell me how can we transfer required build artifact from nexus repository to higher environments using Jenkins build pipeline plugin and what is the use of parametrized trigger plugin in this process

@gir2

This comment has been minimized.

Show comment
Hide comment
@gir2

gir2 Aug 17, 2017

Man, I don´t have any problem to use a key pair with passphrase

gir2 commented Aug 17, 2017

Man, I don´t have any problem to use a key pair with passphrase

@hemendrasinghhbti

This comment has been minimized.

Show comment
Hide comment
@hemendrasinghhbti

hemendrasinghhbti Sep 5, 2017

Thanks for the steps you mentioned above.

hemendrasinghhbti commented Sep 5, 2017

Thanks for the steps you mentioned above.

@neurotempest

This comment has been minimized.

Show comment
Hide comment
@neurotempest

neurotempest Sep 26, 2017

On windows, when Jenkins is running as a service, I also had to make sure that the service was being started as the same user that I generated the ssh key with, to make sure it finds the correct ssh key.

Thanks for the guide!

neurotempest commented Sep 26, 2017

On windows, when Jenkins is running as a service, I also had to make sure that the service was being started as the same user that I generated the ssh key with, to make sure it finds the correct ssh key.

Thanks for the guide!

@nleiva

This comment has been minimized.

Show comment
Hide comment
@nleiva

nleiva Oct 14, 2017

Build Trigger Build when a change is pushed to GitHub has been renamed to GitHub hook trigger for GITScm polling (v1.25.1)

nleiva commented Oct 14, 2017

Build Trigger Build when a change is pushed to GitHub has been renamed to GitHub hook trigger for GITScm polling (v1.25.1)

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