Failing of builds in Snyk CLI
Last updated
Last updated
More information
Snyk privacy policy© 2024 Snyk Limited | All product and company names and logos are trademarks of their respective owners.
The snyk test
command has the following options for failing your builds:
--severity-threshold=low|medium|high|critical
Report only vulnerabilities of the specified level or higher.
--fail-on=all
Fail when there is at least one vulnerability that can be either upgraded or patched.
--fail-on=upgradable
Fail when there is at least one vulnerability that can be upgraded.
--fail-on=patchable
Fail when there is at least one vulnerability that can be patched or vulnerabilities that can be either patched or upgraded.
The Snyk CLI on its own does not have the capability natively to fail tests on more complex use cases. Here are some ways to achieve more complex pass/fail criteria.
Security policies provide the capability to change the severity of a vulnerability, when a Project is tested against an Organization using that policy and the severity matches specific criteria. You could, for example, change the severity of a vulnerability from high to low, and if you run snyk test
with the option --severity-threshold=medium|high
, this previously high severity vulnerability no longer fails the build.
Security policies do not have all attributes available for criteria matching. Refer to the security policy configuration to see what is available.
An example follows of snyk test
with the option --severity-threshold=high
running against a default Organization with no policy applied to it.
The following example shows thesnyk test
command with the option --severity-threshold=high
running against an Organization with a policy that downgrades this particular vulnerability severity to low
. There are no vulnerabilities found.
The CLI has companion tools for Open Source scanning snyk-delta
and snyk-filter
.
snyk-delta
finds the delta of vulnerabilities between the current test and a previously monitored snapshot. This tool is available from npmjs.org, and may be pulled into your CI/CD pipeline by running npm install -g snyk-delta
.
snyk-filter
provides for user-defined pass/fail criteria based on any available data in the snyk test
JSON output. This tool is available from npmjs.org and may be pulled into your CI/CD pipeline by running npm install -g snyk-filter
.
snyk delta
This is a simple example: snyk test --json --print-deps | snyk-delta
This example possibly points to a specific snapshot by specifying Organization and Project coordinates.
snyk test --json --print-deps | snyk-delta --baselineOrg xxx --baselineProject xxx
snyk delta
snyk-delta --baselineOrg xxx --baselineProject xxx --currentOrg xxx --currentProject xxx
Refer to the snyk-delta project on GitHub for more information.
snyk filter
snyk test --json | snyk-filter -f /path/to/example-cvss-9-or-above.yml
snyk filter
snyk-filter
can use any combination of criteria available in the snyk test
JSON output.
You may also have different criteria for display from what will fail the build. This allows you to do things like display all vulnerabilities in the test output while failing only on some specific criteria.
Refer to the snyk-filter project on GitHub for examples and more information.