For the complete documentation index, see llms.txt. This page is also available as Markdown.
Integrate with Bitbucket Pipelines
How to integrate Snyk API and Web with Bitbucket Pipelines
This guide provides step-by-step instructions for integrating Snyk API & Web into your Bitbucket Pipelines.
Overview
This guide focuses on using the Snyk CLI to run scans. The following examples cover a complete end-to-end journey, from configuring your targets in the Snyk UI to running different scan scenarios in your pipeline.
Prerequisites
Configure your scan targets and credentials in the Snyk application before you begin.
Create a target in Snyk
In the Snyk app, navigate to the Targets menu and click Add. Fill out the form and click Add to create the new target.
During this process, Snyk checks connectivity. If your target is internal or not yet deployed, you can bypass any warnings and add the target. For more details, visit How to add a Target.
Before you configure the integration in Bitbucket Pipelines, retrieve the unique target ID from Snyk.
In your Snyk dashboard, select Targets.
From the target list, select the target you want to integrate.
In your browser's address bar, copy the target ID. This is the string of characters immediately following /target/ in the URL.
After you create a target, you must verify the target's domain. Otherwise, your scans are limited to lightning scans. To learn more, visit the importance of domain ownership verification.
Create a Snyk API key
You need an API key with permissions to start a scan on your target. For instructions, visit How to generate an API key.
Step 1: Add your API key and target ID to Bitbucket Pipelines
To run a scan, your pipeline must authenticate with Snyk and know which target to scan. Configure your Snyk API key and target ID as secure repository variables in your Bitbucket Pipelines project.
From your Bitbucket Pipelines project side menu, navigate to Repository settings > Repository variables.
Click Add and create an entry for your Snyk API Key (for example, PROBELY_API_KEY).
Click Add again to create a second entry for your target ID (for example, TARGET_ID).
For enhanced security, always store sensitive values as Bitbucket CI/CD variables. Do not store variables directly in your bitbucket-pipelines.yml file, because they are saved in plain text and visible to anyone who can view the file.
Step 2: Configure your pipeline
Create a bitbucket-pipelines.yml file at the root of your repository and add one of the following code examples based on your use case. You can also find all of them in the Snyk API & Web CI/CD examples repository on GitHub.
Important note on these examples
The following YAML configurations are scanning steps to incorporate into your existing bitbucket-pipelines.yml file.
For example, your pipeline might already have steps to build your code, deploy to a QA environment, and run automated tests. You can add the Snyk scan as another step at any point that makes sense for your workflow, such as after you deploy to QA or staging.
Run a scan on a target in non-blocking mode
This is the simplest configuration. It uses the Snyk CLI to run a scan on a remote target and does not wait for the scan to finish, so the pipeline completes quickly.
Run a scan on a target in blocking mode
This configuration starts a scan and then polls the results, failing the pipeline if any high-severity vulnerabilities are found.
Run a scan on an ephemeral (dynamic) target in blocking mode
This is a more advanced configuration for building, deploying, and scanning an application in a temporary environment. The pipeline creates the environment for a specific purpose and then automatically destroys it during the run.
Ephemeral environments require an agent token, target hostname, and target URL. Store them as variables for better security.
You also need to create a scanning agent in Snyk and configure your target to use it. This process requires the scanning-agent/farcasterd-linux-amd64-0.4.3 file. For detailed instructions, visit How to install a Scanning Agent and How to scan internal applications.
This code example uses Docker to create ephemeral environments. However, you can use any other solution to create your environment.
Advanced scenario: dynamic target creation
This example demonstrates how to use the Snyk CLI to dynamically check for, create, and then scan a target that does not already exist in the Snyk UI.
Step 3: Run the pipeline and view the results
After you commit your bitbucket-pipelines.yml file, you can run the pipeline in Bitbucket Pipelines to test the integration.
After the scan completes, you can view the detailed findings in your Snyk dashboard.