Commit de03a8bc authored by Tiger's avatar Tiger

Detailed status for builds that fail prerequisites

Create FailedUnmetPrerequisites status to allow custom
messaging for builds that were unable to be queued due
to failing to meet prerequisites (eg. failing to create
Kubernetes namespace for deployment).
parent 093629fe
...@@ -16,7 +16,8 @@ module Gitlab ...@@ -16,7 +16,8 @@ module Gitlab
Status::Build::Skipped], Status::Build::Skipped],
[Status::Build::Cancelable, [Status::Build::Cancelable,
Status::Build::Retryable], Status::Build::Retryable],
[Status::Build::Failed], [Status::Build::FailedUnmetPrerequisites,
Status::Build::Failed],
[Status::Build::FailedAllowed, [Status::Build::FailedAllowed,
Status::Build::Unschedule, Status::Build::Unschedule,
Status::Build::Play, Status::Build::Play,
......
# frozen_string_literal: true
module Gitlab
module Ci
module Status
module Build
class FailedUnmetPrerequisites < Status::Extended
def illustration
{
image: 'illustrations/skipped-job_empty.svg',
size: 'svg-430',
title: _('Failed to create resources'),
content: _('Retry this job in order to create the necessary resources')
}
end
def self.matches?(build, _)
build.unmet_prerequisites?
end
end
end
end
end
end
...@@ -336,6 +336,11 @@ FactoryBot.define do ...@@ -336,6 +336,11 @@ FactoryBot.define do
failure_reason 2 failure_reason 2
end end
trait :prerequisite_failure do
failed
failure_reason 10
end
trait :with_runner_session do trait :with_runner_session do
after(:build) do |build| after(:build) do |build|
build.build_runner_session(url: 'https://localhost') build.build_runner_session(url: 'https://localhost')
......
...@@ -123,6 +123,35 @@ describe Gitlab::Ci::Status::Build::Factory do ...@@ -123,6 +123,35 @@ describe Gitlab::Ci::Status::Build::Factory do
expect(status.action_path).to include 'retry' expect(status.action_path).to include 'retry'
end end
end end
context 'when build has unmet prerequisites' do
let(:build) { create(:ci_build, :prerequisite_failure) }
it 'matches correct core status' do
expect(factory.core_status).to be_a Gitlab::Ci::Status::Failed
end
it 'matches correct extended statuses' do
expect(factory.extended_statuses)
.to eq [Gitlab::Ci::Status::Build::Retryable,
Gitlab::Ci::Status::Build::FailedUnmetPrerequisites]
end
it 'fabricates a failed with unmet prerequisites build status' do
expect(status).to be_a Gitlab::Ci::Status::Build::FailedUnmetPrerequisites
end
it 'fabricates status with correct details' do
expect(status.text).to eq 'failed'
expect(status.icon).to eq 'status_failed'
expect(status.favicon).to eq 'favicon_status_failed'
expect(status.label).to eq 'failed'
expect(status).to have_details
expect(status).to have_action
expect(status.action_title).to include 'Retry'
expect(status.action_path).to include 'retry'
end
end
end end
context 'when build is a canceled' do context 'when build is a canceled' do
......
require 'spec_helper'
RSpec.describe Gitlab::Ci::Status::Build::FailedUnmetPrerequisites do
describe '#illustration' do
subject { described_class.new(double).illustration }
it { is_expected.to include(:image, :size, :title, :content) }
end
describe '.matches?' do
let(:build) { create(:ci_build, :created) }
subject { described_class.matches?(build, double) }
context 'when build has not failed' do
it { is_expected.to be_falsey }
end
context 'when build has failed' do
before do
build.drop!(failure_reason)
end
context 'with unmet prerequisites' do
let(:failure_reason) { :unmet_prerequisites }
it { is_expected.to be_truthy }
end
context 'with a different error' do
let(:failure_reason) { :runner_system_failure }
it { is_expected.to be_falsey }
end
end
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