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:
First, ensure your stack has the desired label applied
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 labelsAdding a condition
labels == "your-label-here"in the policy rules to filter notifications