Running CI on a Node.js application hosted on a private repository

- By Abhijit Kini

BACK TO BLOG HOME

In my previous blogs, I completed running a basic Continuous Integration (CI) on a Node.js app hosted on a public repository. Next, I configured a simple unit test for the Node.js app to check for errors each time I did a code commit. 

In this tutorial, I'll cover running CI for the same Node.js application, if it were hosted on a private repository. Hosting code on a private repository source control system is the common way developers/teams operate during software development. The overview of the work flow is to sign in using source control provider credentials, authorizing a one-time access to private repositories, enabling the project, configuring the shippable.ymlfile, completing a successful CI run for the Node.js app.

Before you begin:

Ensure you have -

  • Installed Node.js on your Mac/PC
  • A GitHub or BitBucket account
  • Completed the previous tutorial of running a simple unit test for the Node.js app
  • Signed into Shippable, authorized access to public repositories hosted on your source control provider
  • Have a private repository hosted on GitHub.
    • Note: You could incur a charge for private repositories from GitHub

Private Repository Overview:

Organizations and developer teams that choose not to share their code publicly can sign up for a paid GitHub account so they can host it in private repositories. By controlling access to include team members, software is developed. When you sign into Shippable for the first time, it only asks for access to public repositories. To use and access private repos, you'll have to explicitly enable access to private repos on Shippable, once. Refer our documentation for information on permissions and access details.

For this tutorial, I'll assume this Node.js app, (available publicly to download from GitHub) is hosted on a private repository.

Step 1: Sign In

Go to the Shippable portal and sign in with your source control provider credentials (GitHub in this walk-through).

  • Click on 'GitHub'.

Signing in using GitHub credentials

Step 2: Authorize private repository access

For Shippable to access private repositories on your source control system, you'll need to authorize access by doing a one-time additional step.

  • Go to your Account Settings (gear icon on the top right hand navigation bar)
  • Access the the 'Git Identities' section under the 'Accounts' tab
  • Click 'Enable' for the desired source control system
  • Click 'Authorize application'
  • Provide your source control account password if prompted

Authorize private repository access for continuous integration

Step 3: Enable your project

Source control repos are called Projects within the Shippable platform.  To enable a project:

  • From the 'Home' page, select the appropriate account under 'Subscriptions'.
    • NOTE: Subscriptions can be either at an individual level or at an organizational level on your source control provider.
  • A list of all enabled projects and their latest build status is displayed.
  • Click the 'Enable Project' button to enable a new one.
  • Review the list of all your public and private repos from your source control provider account.
  • Click on 'Enable' button for the desired repo/project.
  • The project is enabled. You can manually trigger a build on Shippable by clicking the 'Build' button or automatically by a code commit or a pull request to your repo.
  • Before triggering a build, it is critical to complete the next step.

Enable a private repository for continuous integration

Step 4: Configure a shippable.yml file

This is an important step that instructs Shippable on the actions to be taken while running CI. Without this file no process takes place on the Shippable platform. The shippable.yml file is created in the root of your repository and for this tutorial, basic sections such as language, language version and a unit test are configured. Use our reference guide to understand the full power and capabilities supported on the Shippable platform.

Shippable yml file for running continuous integration for a private repository

Step 5: Run a successful CI build

Having configured the shippable.yml file at the root of the 'nodejs' local directory, I'll push this change to my 'nodejs' GitHub private repo by running the following commands from my Terminal.

git status

git add .

git commit -m "added shippable.yml"

git push origin master

This action automatically triggers a build on the Shippable platform, where it goes through the actions specified in the shippable.yml file. Having passed all tests, you'll see a green successful build as shown below. 

Successful continuous integration run for a private repository

I've now successfully run CI on a Node.js app hosted on a private repository. In my next blog in this series, I'll set up a visual indication of the Node.js project status, using build badges.


Try Shippable  

Topics: Github, continuous integration (CI), how-to, nodejs, CI/CD, tutorial, private repository