Commit 18726d57 authored by Mayra Cabrera's avatar Mayra Cabrera

Merge branch 'slack-notification-retry-success-skip' into 'master'

Show only completely failed CI jobs in notifications

See merge request gitlab-org/gitlab!28284
parents 2e6280a6 0f8d4ab7
...@@ -34,7 +34,9 @@ module ChatMessage ...@@ -34,7 +34,9 @@ module ChatMessage
@duration = pipeline_attributes[:duration].to_i @duration = pipeline_attributes[:duration].to_i
@finished_at = pipeline_attributes[:finished_at] ? Time.parse(pipeline_attributes[:finished_at]).to_i : nil @finished_at = pipeline_attributes[:finished_at] ? Time.parse(pipeline_attributes[:finished_at]).to_i : nil
@pipeline_id = pipeline_attributes[:id] @pipeline_id = pipeline_attributes[:id]
@failed_jobs = Array(data[:builds]).select { |b| b[:status] == 'failed' }.reverse # Show failed jobs from oldest to newest
# Get list of jobs that have actually failed (after exhausting all retries)
@failed_jobs = actually_failed_jobs(Array(data[:builds]))
@failed_stages = @failed_jobs.map { |j| j[:stage] }.uniq @failed_stages = @failed_jobs.map { |j| j[:stage] }.uniq
@project = Project.find(data[:project][:id]) @project = Project.find(data[:project][:id])
...@@ -90,6 +92,17 @@ module ChatMessage ...@@ -90,6 +92,17 @@ module ChatMessage
private private
def actually_failed_jobs(builds)
succeeded_job_names = builds.map { |b| b[:name] if b[:status] == 'success' }.compact.uniq
failed_jobs = builds.select do |build|
# Select jobs which doesn't have a successful retry
build[:status] == 'failed' && !succeeded_job_names.include?(build[:name])
end
failed_jobs.uniq { |job| job[:name] }.reverse
end
def fancy_notifications? def fancy_notifications?
Feature.enabled?(:fancy_pipeline_slack_notifications, default_enabled: true) Feature.enabled?(:fancy_pipeline_slack_notifications, default_enabled: true)
end end
......
---
title: Make pipeline info in chat notifications concise
merge_request: 28284
author:
type: changed
...@@ -431,6 +431,57 @@ describe ChatMessage::PipelineMessage do ...@@ -431,6 +431,57 @@ describe ChatMessage::PipelineMessage do
end end
end end
context "when jobs succeed on retries" do
before do
args[:builds] = [
{ id: 1, name: "job-1", status: "failed", stage: "stage-1" },
{ id: 2, name: "job-2", status: "failed", stage: "stage-2" },
{ id: 3, name: "job-3", status: "failed", stage: "stage-3" },
{ id: 7, name: "job-1", status: "failed", stage: "stage-1" },
{ id: 8, name: "job-1", status: "success", stage: "stage-1" }
]
end
it "do not return a job which succeeded on retry" do
expected_jobs = [
"<http://example.gitlab.com/-/jobs/3|job-3>",
"<http://example.gitlab.com/-/jobs/2|job-2>"
]
expect(subject.attachments.first[:fields][3]).to eq(
title: "Failed jobs",
value: expected_jobs.join(", "),
short: true
)
end
end
context "when jobs failed even on retries" do
before do
args[:builds] = [
{ id: 1, name: "job-1", status: "failed", stage: "stage-1" },
{ id: 2, name: "job-2", status: "failed", stage: "stage-2" },
{ id: 3, name: "job-3", status: "failed", stage: "stage-3" },
{ id: 7, name: "job-1", status: "failed", stage: "stage-1" },
{ id: 8, name: "job-1", status: "failed", stage: "stage-1" }
]
end
it "returns only first instance of the failed job" do
expected_jobs = [
"<http://example.gitlab.com/-/jobs/3|job-3>",
"<http://example.gitlab.com/-/jobs/2|job-2>",
"<http://example.gitlab.com/-/jobs/1|job-1>"
]
expect(subject.attachments.first[:fields][3]).to eq(
title: "Failed jobs",
value: expected_jobs.join(", "),
short: true
)
end
end
context "when the CI config file contains a YAML error" do context "when the CI config file contains a YAML error" do
let(:has_yaml_errors) { true } let(:has_yaml_errors) { true }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment