This guide assumes you already have a Codeship account and your project is stored on GitHub or Bitbucket. Questions? Join our chat.

Integrating with Codeship

Continuous Deployment services like Codeship make it possible to publish your project on Surge, each time you push to a GitHub or Bitbucket repository.

This guide will walk you through:

  1. Getting your Surge token, so Codeship can login to Surge on your behalf
  2. Adding Surge as a devDependency, so Codeship can install Surge
  3. Setting up your project on Codeship, so you can publish each time you push to GitHub or Bitbucket

Follow along

An open source companion to this guide is available on GitHub.

Getting your Surge token

First, you’ll need your token from the Surge CLI. This secret key lets services like Codeship login and publish projects on your behalf. Get your Surge token by running the following command in your terminal:

surge token

You’ll be asked to login again, and afterwards your token will be displayed like this:

token: a142e09a6b13a21be512b141241c7123
Getting your token from [the Surge CLI](/help/getting-started-with-surge).

Adding Surge as a devDependency to a package.json file

Codeship’s machines won’t have Surge installed by default, so you also need to save Surge as a development dependency in your project. This lets Codeship know it needs to install Surge to publish your project.

You can do this by creating a package.json file if you don’t have one already. Run the following command in your terminal to be walked through making this file (you can hit enter to accept the defaults):

npm init

You will end up with a file that looks something like this one.

Next, run this command to save Surge as a devDependency, so Codeship will install it:

npm install --save-dev surge

Add your project’s repository to Codeship

Now you can login and setup a new project on Codeship. Add your project’s GitHub or Bitbucket repository to your Codeship projects:

Add the GitHub or Bitbucket repository your project is stored in. This example is using the surge-sh/example-codeshiprepo.

Define your Setup and Test Commands

Now you’re ready to run surge on Codeship. Your Codeship setup commands run before the deployment command.

Your setup commands should look like this:

# Install the latest version of Node.js
nvm install stable
nvm use stable

# Install Surge as a devDependency
npm install

After you push you successfully to your repository, Codeship will run your Test Pipeline commands:

# Run your tests (if you have any)
npm test

Add Environment Variables

Press Environment Variables next, and you’ll be able to secretly add your email address and token so Codeship can login to Surge for you:

_Environment Variables_ is listed under your project settings.

Create one environment variable called:


…and set it to the email address you use with Surge. Next, add another environment variable called:


…and set it to your Surge token.

Adding `SURGE_LOGIN` and `SURGE_TOKEN` as environment variables.

Add a deployment script

Push to your repository, and your Setup and Test commands should run, triggering your tests to run on Codeship. Now, Codeship will let you move onto adding a script for Continuous Deployment. You can press the button labeled Set up Continuous Deployment or access this section under your project settings:

Adding a custom script for continuous deployment.

Add a Custom Script and enter the command you want to run with Surge, for example:

surge --project ./ --domain

Now, when you push your poject to GitHub or Bitbucket again, this command will be run and your project will get published automatically.