Commit 4503240a authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch 'fix/gb/fix-skipped-pipeline-with-allowed-to-fail-jobs' into 'master'

Fix pipeline status when allowed to fail jobs present

Closes #29059

See merge request !11166
parents 07f6ab2b caf6b991
......@@ -11,18 +11,21 @@ module HasStatus
class_methods do
def status_sql
scope = respond_to?(:exclude_ignored) ? exclude_ignored : all
builds = scope.select('count(*)').to_sql
created = scope.created.select('count(*)').to_sql
success = scope.success.select('count(*)').to_sql
manual = scope.manual.select('count(*)').to_sql
pending = scope.pending.select('count(*)').to_sql
running = scope.running.select('count(*)').to_sql
skipped = scope.skipped.select('count(*)').to_sql
canceled = scope.canceled.select('count(*)').to_sql
scope_relevant = respond_to?(:exclude_ignored) ? exclude_ignored : all
scope_warnings = respond_to?(:failed_but_allowed) ? failed_but_allowed : none
builds = scope_relevant.select('count(*)').to_sql
created = scope_relevant.created.select('count(*)').to_sql
success = scope_relevant.success.select('count(*)').to_sql
manual = scope_relevant.manual.select('count(*)').to_sql
pending = scope_relevant.pending.select('count(*)').to_sql
running = scope_relevant.running.select('count(*)').to_sql
skipped = scope_relevant.skipped.select('count(*)').to_sql
canceled = scope_relevant.canceled.select('count(*)').to_sql
warnings = scope_warnings.select('count(*) > 0').to_sql.presence || 'false'
"(CASE
WHEN (#{builds})=(#{skipped}) AND (#{warnings}) THEN 'success'
WHEN (#{builds})=(#{skipped}) THEN 'skipped'
WHEN (#{builds})=(#{success}) THEN 'success'
WHEN (#{builds})=(#{created}) THEN 'created'
......
---
title: Fix CI/CD status in case there are only allowed to failed jobs in the pipeline
merge_request: 11166
author:
......@@ -284,6 +284,41 @@ describe CommitStatus, :models do
end
end
describe '.status' do
context 'when there are multiple statuses present' do
before do
create_status(status: 'running')
create_status(status: 'success')
create_status(allow_failure: true, status: 'failed')
end
it 'returns a correct compound status' do
expect(described_class.all.status).to eq 'running'
end
end
context 'when there are only allowed to fail commit statuses present' do
before do
create_status(allow_failure: true, status: 'failed')
end
it 'returns status that indicates success' do
expect(described_class.all.status).to eq 'success'
end
end
context 'when using a scope to select latest statuses' do
before do
create_status(name: 'test', retried: true, status: 'failed')
create_status(allow_failure: true, name: 'test', status: 'failed')
end
it 'returns status according to the scope' do
expect(described_class.latest.status).to eq 'success'
end
end
end
describe '#before_sha' do
subject { commit_status.before_sha }
......
......@@ -48,7 +48,7 @@ describe HasStatus do
[create(type, status: :failed, allow_failure: true)]
end
it { is_expected.to eq 'skipped' }
it { is_expected.to eq 'success' }
end
context 'success and canceled' do
......
......@@ -62,6 +62,10 @@ describe Ci::ProcessPipelineService, '#execute', :services do
fail_running_or_pending
expect(builds_statuses).to eq %w(failed pending)
fail_running_or_pending
expect(pipeline.reload).to be_success
end
end
......
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