How do I make a notification policy trigger only for stacks with specific labels?

Last updated: July 14, 2025

Context

When creating a notification policy in Spacelift, you may want to send notifications only when stacks with specific labels fail. By default, notification policies act at a space level meaning the will be evaluated on any project in the spaces they have access to.

Answer

To make a notification policy trigger only for stacks with specific labels, you need to:

  1. First, ensure your stack has the desired label applied

  2. In your notification policy, add a label check condition. Here's an example policy that sends Slack notifications only for failed stacks with a specific label:

package spacelift

import future.keywords.contains
import future.keywords.if
import future.keywords.in

ir := input.run_updated

# Extract labels from the stack
labels := input.run_updated.stack.labels[_]

slack contains {
    "channel_id": "YOUR_CHANNEL_ID",
    "message": msg,
} if {
    failed
    labels == "created_by:region-manifest"  # Check for specific label
    msg := sprintf("The run failed, you can review the logs here: %s", [run])
}

The key parts that make this work are:

  • Using labels := input.run_updated.stack.labels[_] to extract the stack labels

  • Adding a condition labels == "your-label-here" in the policy rules to filter notifications