Skip to content

Commit

Permalink
Fail pipeline when rule is triggered, and it has the failPipeline action
Browse files Browse the repository at this point in the history
  • Loading branch information
viktigpetterr committed Jan 18, 2023
1 parent 1d8e700 commit 3147f75
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
9 changes: 6 additions & 3 deletions pkg/automation/automation.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,13 @@ func (rule *Rule) Print(mirror io.Writer) {
fmt.Println()
}

// FailPipeline checks if rule should fail the pipeline
func (rule *Rule) FailPipeline() bool {
for _, action := range rule.RuleActions {
if action == "failPipeline" {
return true
if rule.Triggered {
for _, action := range rule.RuleActions {
if action == "failPipeline" {
return true
}
}
}

Expand Down
14 changes: 14 additions & 0 deletions pkg/automation/automation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,17 @@ func TestFailPipeline(t *testing.T) {
t.Error("failed to assert that rule failed")
}
}

func TestFailPipelineUnTriggered(t *testing.T) {
rule := Rule{
RuleDescription: "Rule description",
RuleActions: []string{"warnPipeline", "email", "failPipeline"},
RuleLink: "link",
HasCves: false,
Triggered: false,
TriggerEvents: nil,
}
if rule.FailPipeline() {
t.Error("failed to assert that rule passed")
}
}

0 comments on commit 3147f75

Please sign in to comment.