This article is about General Codeship Configuration.

Using Snyk For Security Analysis

You'll need roughly 2 minutes to read this article.

About Snyk

Snyk is an automated way to check for security vulnerabilities with your dependencies.

Starting with Snyk and Codeship is fast and easy. The Snyk documentation does a great job of providing more information, in addition to the setup instructions below.

Codeship Pro

Adding Token

To start, you need to add your SNYK_TOKEN to the encrypted environment variables that you encrypt and include in your codeship-services.yml file.

CLI Configuration

To use Snyk in your CI/CD process, you’ll need to add the Snyk CLI to a service in your codeship-services.yml file.

To add the Snyk CLI, you will need to add the following command to the Dockerfile for the service you want to run Snyk on:

RUN npm install -g snyk

Note that this requires the Dockerfile to also have Node and NPM available, to use the Snyk CLI.

Running A Scan

Once your Snyk token is loaded via your environment variables and you have defined a service that installs the Snyk CLI, you can run a Snyk scan during your CI/CD pipeline by passing the Snyk CLI commands via the service you have it installed in.

We will combine the Snyk authentication and Snyk scan commands into a script file that we call from a step:

- name: Snyk
  service: app
  command: snyk.sh

Inside this snyk.sh script, you will have something similar to:

snyk auth
snyk test

Note that the above snyk auth command will use the SNYK_TOKEN environment variable you set earlier for authentication.

Codeship Basic

Adding Token

To start, you need to add your SNYK_TOKEN to your to your project’s environment variables.

You can do this by navigating to Project Settings and then clicking on the Environment tab.

CLI Configuration

To use Snyk in your CI/CD process, you’ll need to install the Snyk CLI via your project’s setup commands:

npm install -g snyk

Running A Scan

Once your Snyk token is loaded via your environment variables and you have installed the Snyk CLI, you can run a Snyk scan during your CI/CD pipeline.

You will need to add the following commands to your project’s setup and test commands

snyk auth
snyk test

Note that the above snyk auth command will use the SNYK_TOKEN environment variable you set earlier for authentication.