Classic Docs
Docs Navigation

Building a project with private gems

Either use a hosted private gem repository such as Gemfury, or follow this procedure:

# - Get an OAuth Token from GitHub

First you will need to get an OAuth Token from GitHub using your own username and "note"

curl -u 'masonforest' -d '{"scopes":["repo"], "note":"Semaphore CI private gem"}'

# - Authenticate bundler to GitHub via OAuth Token

Add this line to your Gemfile replacing "your_token" with the token you got from first step. In this example we are installing the 'ventana' gem:

gem 'ventana', git: ""

# More secure alternative:

# Storing the OAuth token in an environment variable

For additional security you can store your OAuth token in an environment variable. This way your token is not included in your codebase which is insecure. However this technique require form you to export OAuth token in your development environment too (Best way is to export it in ~/.zshrc or ~/.bashrc).

Change the line in your Gemfile to

gem 'ventana', git: "https://#{ENV['GITHUB_TOKEN']}"

Then export token on Semaphore using the token you got from above:

export GITHUB_TOKEN=your_token

Now bundle localy and you are ready to build on Semaphore!

# Third alternative: additional SSH key

As of November 2013 Semaphore supports saving and using configuration files, including SSH keys. Follow this guide to set up an additional SSH key which can give your build or deploy permissions to pull private dependencies.

Since the Git client uses only the first key from the ssh-agent we'd like to suggest using one of the methods listed above.

# Create a machine user on Github

If project's dependencies are hosted on the Github, you can enable Semaphore environment to fetch repositories with these steps:

  1. Create a machine user with access to repositories
  2. Create new SSH key pair for the purpose of automation
  3. Add private SSH key to the project as a configuration file in the project settings
  4. Add the public SSH key to the user settings for the machine user

# Download a private gem in a project - practical example

If your project uses a gem that is coming from private repository which requires authentication, you can clone repositories from within Semaphore and the SSH protocol should be used in Git. You may set this up by:

  1. Changing the URLs in .gitsubmodules to SSH. For example, when private submodule is hosted on Github, URL should be similar to the following:
url =<repo_owner>/<repo>.git
  1. Creating a machine user on Github and allowing it to access your repositories.

2.1. Generate a new SSH key-pair for the machine user (public part goes to Github), 2.2. Add the private part to Semaphore Classic as a configuration file.

Semaphore Docs are open source — Edit on GitHub


Occasional lightweight product and blog updates. Unsubscribe at any time.

2009-2019 © Rendered Text. All rights reserved. Terms of Service, Privacy policy, Security.