Jenkins plugin integration with Snyk

Snyk offers a native plugin for Jenkins that is based on the Snyk CLI, to test and monitor Projects for vulnerabilities in your pipelines.

The Snyk Jenkins plugin supports Snyk Open Source. If you plan to include Snyk Code, Snyk Container, and Snyk IaC scans in your pipeline, use the generic Snyk CLI.

For more information, see the Snyk Jenkins Plugin repository.

Follow the steps in each section of this document to use the Snyk Jenkins plugin:

  1. Install the Snyk Security Jenkins Plugin.

  2. Configure a Snyk installation.

  3. Configure a Snyk API token credential.

  4. Add Snyk Security to your Project.

  5. Run a build and view your Snyk report.

1. Install the Snyk Security Jenkins Plugin

  • From your Jenkins dashboard, go to Manage Jenkins, Plugins and select the Available plugins tab.

  • Search for Snyk Security.

  • Install the plugin.

2. Configure a Snyk installation

  • Go to Manage Jenkins, Tools.

  • Add a Snyk Installation.

  • Configure the Installation.

  • Remember the Name for use when configuring the build step.

Automatic installations

The plugin can download the latest version of Snyk binaries and keep them up-to-date for you.

Manual installations

  • Download the following binaries. Choose the binary suitable for your agent's operating system:

  • Place the binaries in a single directory on your agent.

    • Do not change the filename of the binaries.

    • Ensure you have the correct permissions to execute the binaries.

  • Provide the absolute path to the directory under Installation directory.

Custom API endpoints

By default, Snyk uses the https://api.snyk.io endpoint. It is possible to configure Snyk to use a different endpoint by changing the SNYK_API environment variable:

  • Go to Manage Jenkins, System.

  • Under Global Properties check the Environment variables option.

  • Click Add.

  • Set the name to SNYK_API and the value to the custom endpoint.

For more information see Configure Snyk CLI to connect to Snyk API.

3. Configure a Snyk API token credential

  • Get your Snyk API Token.

  • Go to Manage Jenkins, Credentials.

  • Choose a Store.

  • Choose a Domain.

  • Go to Add Credentials.

  • Select Snyk API Token.

  • Configure the Credentials.

  • Remember the ID for use when configuring the build step.

4. Add Snyk Security to your Project

This step depends on whether you are using Freestyle Projects or Pipeline Projects.

Freestyle Projects

  • Select a Project.

  • Go to Configure.

  • Under Build, select Add build step and Invoke Snyk Security Task.

  • Configure as needed. Click the ? icons for more information about each option.

Pipeline Projects

Use the snykSecurity step as part of your pipeline script. You can use the Snippet Generator to generate the code from a web form and copy it into your pipeline. Refer to the following example.

pipeline {
  agent any

  stages {
    stage('Build') {
      steps {
        echo 'Building...'
      }
    }
    stage('Test') {
      steps {
        echo 'Testing...'
        snykSecurity(
          snykInstallation: '<Your Snyk Installation Name>',
          snykTokenId: '<Your Snyk API Token ID>',
          // place other parameters here
        )
      }
    }
    stage('Deploy') {
      steps {
        echo 'Deploying...'
      }
    }
  }
}

You can pass the following parameters to yoursnykSecurity step.

snykInstallation (required)

Snyk Installation Name, as configured in step 2. Configure a Snyk installation.

snykTokenId (optional, default: _none_)

Snyk API Token Credential ID., as configured in step 3. Configure a Snyk API token credential.

If you prefer to provide the Snyk API token another way, such as using alternative credential bindings, you must provide a SNYK_TOKEN build environment variable.

failOnIssues (optional, default: true)

Whether the step should fail if issues and vulnerabilities are found.

failOnError (optional, default: true)

Whether the step should fail if Snyk fails to scan the project due to an error. Errors include scenarios like: failing to download Snyk's binaries, improper Jenkins setup, bad configuration, and server errors.

monitorProjectOnBuild (optional, default: _none_)

Whether to monitor the Project on every build by taking a snapshot of its current dependencies on Snyk.io. Selecting this option will keep you notified about newly disclosed vulnerabilities and remediation options in the Project.

organisation (optional, default: _automatic_)

The Snyk