Commit df089f6c authored by Erick Bajao's avatar Erick Bajao

Specify failing dependencies in the callout message

To avoid unexpected side-effects elsewhere, we only
return the detailed message in the build details entity.
This is because we only want to show this message in the
job details page.
parent 6069739e
......@@ -758,6 +758,10 @@ module Ci
true
end
def invalid_dependencies
dependencies.reject(&:valid_dependency?)
end
def runner_required_feature_names
strong_memoize(:runner_required_feature_names) do
RUNNER_FEATURES.select do |feature, method|
......
......@@ -121,4 +121,28 @@ class BuildDetailsEntity < JobEntity
def can_admin_build?
can?(request.current_user, :admin_build, project)
end
def callout_message
return super unless build.failure_reason.to_sym == :missing_dependency_failure
docs_url = "https://docs.gitlab.com/ce/ci/yaml/README.html#when-a-dependent-job-will-fail"
[
failure_message.html_safe,
help_message(docs_url).html_safe
].join("<br />")
end
def invalid_dependencies
build.invalid_dependencies.map(&:name).join(', ')
end
def failure_message
_("There were missing dependencies from the following job(s): %{invalid_dependencies}") %
{ invalid_dependencies: invalid_dependencies }
end
def help_message(docs_url)
_("Please refer to <a href=\"%{docs_url}\">%{docs_url}</a>") % { docs_url: docs_url }
end
end
---
title: Include in the callout message a list of jobs that caused missing dependencies
failure.
merge_request: 18219
author:
type: added
......@@ -3925,4 +3925,14 @@ describe Ci::Build do
end
end
end
describe '#invalid_dependencies' do
let!(:pre_stage_job_valid) { create(:ci_build, :manual, pipeline: pipeline, name: 'test1', stage_idx: 0) }
let!(:pre_stage_job_invalid) { create(:ci_build, :success, :expired, pipeline: pipeline, name: 'test2', stage_idx: 1) }
let!(:job) { create(:ci_build, :pending, pipeline: pipeline, stage_idx: 2, options: { dependencies: %w(test1 test2) }) }
it 'returns invalid dependencies' do
expect(job.invalid_dependencies).to eq([pre_stage_job_invalid])
end
end
end
......@@ -123,6 +123,24 @@ describe BuildDetailsEntity do
end
it { is_expected.to include(failure_reason: 'unmet_prerequisites') }
it { is_expected.to include(callout_message: CommitStatusPresenter.callout_failure_messages[:unmet_prerequisites]) }
end
context 'when the build has failed due to a missing dependency' do
let!(:test1) { create(:ci_build, :success, :expired, pipeline: pipeline, name: 'test1', stage_idx: 0) }
let!(:test2) { create(:ci_build, :success, :expired, pipeline: pipeline, name: 'test2', stage_idx: 1) }
let!(:build) { create(:ci_build, :pending, pipeline: pipeline, stage_idx: 2, options: { dependencies: %w(test1 test2) }) }
let(:message) { subject[:callout_message] }
before do
build.drop!(:missing_dependency_failure)
end
it { is_expected.to include(failure_reason: 'missing_dependency_failure') }
it 'includes the failing dependencies in the callout message' do
expect(message).to include('test2, test1')
end
end
context 'when a build has environment with latest deployment' do
......
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