Continuous Integration Setup with Jenkins for a Node.js Project – Part 2

In my previous post, we went over how to install Jenkins on your own server.  Now, we’ll set up all the basic configurations necessary in Jenkins and integrating it with GitHub.

Basic configurations in Jenkins

At this point, anybody who’s anybody can do things in our Jenkins server.  So let’s set up security in Jenkins.  We’re going to use a project-based matrix security which will allow us to see users and their permissions in a matrix format.

From the Jenkins dashboard:

  1. Click “Manage Jenkins”
  2. Click “Setup security” button on the top right (or alternatively, click on “Configure Global Security”).

In Configure Global Security page:

  1. Check “Enable security”
  2. Scroll to “Security Realm,” select “Jenkins’ own user database” and check “Allow users to sign up.”
  3. Click “Save” button

Next, we’ll set up an administrative account.

  1. Click “Sign up” in the top-right corner of the screen.
  2. Fill out the form (username, password, confirm password, full name, e-mail address)
  3. Click “Submit” button

Go back to the “Configure Global Security” page:

  1. Scroll to “Jenkins’ own user database,” un-check “Allow users to sign up.”
  2. Click “Save” button.  That means the “Sign up” link in the top-right corner of the screen will no longer show.
  3. Still on the same page, scroll to “Authorization” select “Project-based Matrix Authorization Strategy.”  A matrix diagram will appear.
  4. Fill out your username in “User/group to add” input box and click “Add”
  5. Your username will appear in the matrix.  Next to your username, check “Administer.”
  6. Click “Save” button.  You are now the admin!

Installing GitHub Plugin

In order to integrate with GitHub, we need to install the plugin.

  1. Click “Manage Jenkins” on the menu on the left.
  2. In the “Manage Jenkins” page, click “Manage Plugins.”
  3. In “Manage Plugins” page, click on the “Available” tab.
  4. Search for the “GitHub plugin” and checkmark it as it appears in the search results.  Click “Install without restart” and checkmark “Restart Jenkins when installation is complete and no jobs are running” if it requires a Jenkins restart.

Integrating with GitHub

  1. Click “Manage Jenkins”
  2. Click “Configure System”
  3. Scroll to “Jenkins location,” ensure that it has a public facing URL so that GitHub can push events to it.
  4. Click “Save” button.

Next, go to your account in GitHub.  You will need to generate a token to use with the GitHub API.

  1. Go to “Settings”
  2. Go to “Personal access tokens”
  3. Click “Generate new token”
  4. Token description can be something like “Jenkins”
  5. Ensure that repo, public_repo, gist, and user are all checked.  The rest are un-checked.
  6. Copy the generated token.

Go back to your Jenkins dashboard.

  1. Click “Configure System”
  2. Scroll to “GitHub Web Hook”
  3. Select “Let Jenkins auto-manage hook URLs
  4. Under “GitHub credentials,” fill out Username and OAuth token (the token you just copied from GitHub) and click “Test credential.”
  5. Click “Save” button

GitHub web hooks should work now.  More setup is needed for pulling from private repositories.

  1. Click “Credentials” in side menu
  2. Click “Global Credentials”
  3. Click “Add Credentials”
  4. Fill out the form for Username, Password, Description
    1. Kind: username with password
    2. Scope – Global
    3. Username – GitHub username
    4. Password – use your token
    5. Description – You can call it “<GitHub username> (GitHub)” and replace <GitHub username> with your GitHub username
  5. Click OK button

Congratulations, GitHub has been integrated into Jenkins!  In my next post, we’ll learn how to set up our first Node.js project in Jenkins.

Leave a Reply

Your email address will not be published. Required fields are marked *