For the complete documentation index, see llms.txt. This page is also available as Markdown.

Set up Slack notifications for detected issues in STO

Set up Slack notifications based on severity levels

This topic describes how to generate Slack notifications for STO-related events such as:

  • A scan detected new vulnerabilities.

  • A scan detected critical- or high-severity vulnerabilities.

  • A scan step failed because it crossed my Fail on Severity threshold or violated one or more of my OPA policies.

To set up Slack notifications, you add a simple script to your pipeline that does the following:

  1. Determines whether to send a notification.

  2. Creates a string variable with your notification content.

  3. Posts the notification to your Slack webhook.

Before you begin

  1. Add an incoming webhook to your Slack app.

  2. Run a cURL command to verify that you can post notifications to the webhook.

    For information about these steps, go to Sending messages using incoming webhooks in the Slack documentation.

  3. Create a Harness secret for your webhook URL.

Add the script to your pipeline

  1. In your scan stage, add a Run step after the scan step.

  2. Set the shell type. This example workflow uses Bash.

  3. If you want to send a Slack when the scan step fails, add a failure strategy to ignore the failure for all errors.

    Send a Slack when the scan step fails
  4. Set up your script as follows.

Add variables for your pipeline and scan results

This is optional but can make your script easier to understand and update.

Here's an example:

To get the full expression for an output variable:

  • Go to the Pipeline Execution page for a previous run of your STO pipeline.

  • Navigate to Pipeline > scan_stage_id > Output.

  • Hover next to the variable name to access Click to Copy.

    Add shared path for scan results

Send the notification?

If you want to send notifications based on your scan results, check the output variables from the previous scan step. If all the variables you're interested in are zero, there's no need to send a notification.

Generate the notification content

Create a string variable for your notification content. Include the pipeline URL, the scan output, and any other relevant information. For example:

Post the notification

Add a cURL command to post the notification to your Slack webhook. In this example, $slack_hook is the Harness secret for the Slack webhook URL.

Script and pipeline examples for STO Slack notifications

Notify on scan results

This pipeline does the following:

  1. Runs a Trivy scan on a container image.

  2. Sends a Slack notification if the scan results include any CRITICAL, HIGH, NEW_CRITICAL, or NEW_HIGH vulnerabilities.

Add shared path for scan results
Full script - Try it yourself

To add this script to an existing pipeline:

  1. Do the steps in Before you begin.

  2. Add the script to your pipeline.

  3. Update the following placeholders:

    • FULL_EXPRESSION_OUTPUT_VARIABLE_NEW_CRITICAL

    • FULL_EXPRESSION_OUTPUT_VARIABLE_NEW_HIGH

      You can copy and paste these expressions from a previous pipeline execution.

    • YOUR_HARNESS_PIPELINE_URL

    • YOUR_SLACK_CHANNEL

    • YOUR_SLACK_USERNAME

    • YOUR_SLACK_WEBHOOK_URL_SECRET

  4. Save and run the pipeline.

YAML pipeline - Try it yourself

To run this pipeline yourself:

  1. Do the steps in Before you begin.

  2. Create a new Harness pipeline.

  3. Select the YAML view and copy/paste the YAML pipeline below.

  4. Update the following placeholders:

    • YOUR_HARNESS_PIPELINE_URL

    • YOUR_SLACK_CHANNEL

    • YOUR_SLACK_USERNAME

    • YOUR_SLACK_WEBHOOK_URL_SECRET

  5. Save and run the pipeline.

Notify when the scan step fails

This pipeline does the following:

  1. Runs a Trivy scan on a container image.

  2. Sends a Slack notification if the scan step fails — for example, if it exceeds the Fail on Severity threshold or violates an OPA policy.

Add shared path for scan results
Full script - Try it yourself

To add this script to an existing pipeline:

  1. Do the steps in Before you begin.

  2. Add the script to your pipeline.

  3. Update the following placeholders:

    • FULL_EXPRESSION_OUTPUT_VARIABLE_CRITICAL

    • FULL_EXPRESSION_OUTPUT_VARIABLE_HIGH

    • FULL_EXPRESSION_OUTPUT_VARIABLE_NEW_CRITICAL

    • FULL_EXPRESSION_OUTPUT_VARIABLE_NEW_HIGH

      You can copy and paste these expressions from a previous pipeline execution.

    • YOUR_HARNESS_PIPELINE_URL

    • YOUR_SLACK_CHANNEL

    • YOUR_SLACK_USERNAME

    • YOUR_SLACK_WEBHOOK_URL_SECRET

  4. Save and run the pipeline.

YAML pipeline - Try it yourself

To run this pipeline yourself:

  1. Do the steps in Before you begin.

  2. Create a new Harness pipeline.

  3. Select the YAML view and copy/paste the YAML pipeline below.

  4. Update the following placeholders:

    • YOUR_HARNESS_PIPELINE_URL

    • YOUR_SLACK_CHANNEL

    • YOUR_SLACK_USERNAME

    • YOUR_SLACK_WEBHOOK_URL_SECRET

  5. Save and run the pipeline.

Last updated

Was this helpful?