Commit 6b0bfda8 authored by Kamil Trzciński's avatar Kamil Trzciński

Add `runner_unsupported` CI failure

parent 6cccf59c
...@@ -174,10 +174,6 @@ module Ci ...@@ -174,10 +174,6 @@ module Ci
end end
end end
before_transition any => [:running] do |build|
build.validates_dependencies! unless Feature.enabled?('ci_disable_validates_dependencies')
end
after_transition pending: :running do |build| after_transition pending: :running do |build|
build.ensure_metadata.update_timeout_state build.ensure_metadata.update_timeout_state
end end
...@@ -343,6 +339,10 @@ module Ci ...@@ -343,6 +339,10 @@ module Ci
{ trace_sections: true } { trace_sections: true }
end end
def runner_required_features
%w(variables)
end
def merge_request def merge_request
return @merge_request if defined?(@merge_request) return @merge_request if defined?(@merge_request)
...@@ -581,7 +581,9 @@ module Ci ...@@ -581,7 +581,9 @@ module Ci
options[:dependencies]&.empty? options[:dependencies]&.empty?
end end
def validates_dependencies! def valid_build_dependencies?
return unless Feature.enabled?('ci_disable_validates_dependencies')
dependencies.each do |dependency| dependencies.each do |dependency|
raise MissingDependenciesError unless dependency.valid_dependency? raise MissingDependenciesError unless dependency.valid_dependency?
end end
...@@ -594,6 +596,12 @@ module Ci ...@@ -594,6 +596,12 @@ module Ci
true true
end end
def supported_runner?(features)
runner_required_features.all? do |feature_name|
features[feature_name]
end
end
def hide_secrets(trace) def hide_secrets(trace)
return unless trace return unless trace
......
...@@ -46,7 +46,8 @@ class CommitStatus < ActiveRecord::Base ...@@ -46,7 +46,8 @@ class CommitStatus < ActiveRecord::Base
api_failure: 2, api_failure: 2,
stuck_or_timeout_failure: 3, stuck_or_timeout_failure: 3,
runner_system_failure: 4, runner_system_failure: 4,
missing_dependency_failure: 5 missing_dependency_failure: 5,
runner_unsupported: 6,
} }
## ##
......
...@@ -6,7 +6,8 @@ class CommitStatusPresenter < Gitlab::View::Presenter::Delegated ...@@ -6,7 +6,8 @@ class CommitStatusPresenter < Gitlab::View::Presenter::Delegated
api_failure: 'There has been an API failure, please try again', api_failure: 'There has been an API failure, please try again',
stuck_or_timeout_failure: 'There has been a timeout failure or the job got stuck. Check your timeout limits or try again', stuck_or_timeout_failure: 'There has been a timeout failure or the job got stuck. Check your timeout limits or try again',
runner_system_failure: 'There has been a runner system failure, please try again', runner_system_failure: 'There has been a runner system failure, please try again',
missing_dependency_failure: 'There has been a missing dependency failure' missing_dependency_failure: 'There has been a missing dependency failure',
# COMMENTED to check if tests gonna fail: runner_unsupported: 'Your runner is unsupported. Upgrade runner to use new features of your Pipeline',
}.freeze }.freeze
presents :build presents :build
...@@ -20,6 +21,6 @@ class CommitStatusPresenter < Gitlab::View::Presenter::Delegated ...@@ -20,6 +21,6 @@ class CommitStatusPresenter < Gitlab::View::Presenter::Delegated
end end
def unrecoverable? def unrecoverable?
script_failure? || missing_dependency_failure? script_failure? || missing_dependency_failure? || runner_unsupported?
end end
end end
...@@ -41,16 +41,10 @@ module Ci ...@@ -41,16 +41,10 @@ module Ci
begin begin
# In case when 2 runners try to assign the same build, second runner will be declined # In case when 2 runners try to assign the same build, second runner will be declined
# with StateMachines::InvalidTransition or StaleObjectError when doing run! or save method. # with StateMachines::InvalidTransition or StaleObjectError when doing run! or save method.
begin if assign_runner!(build, params)
build.runner_id = runner.id
build.runner_session_attributes = params[:session] if params[:session].present?
build.run!
register_success(build) register_success(build)
return Result.new(build, true) # rubocop:disable Cop/AvoidReturnFromBlocks return Result.new(build, true) # rubocop:disable Cop/AvoidReturnFromBlocks
rescue Ci::Build::MissingDependenciesError
build.drop!(:missing_dependency_failure)
end end
rescue StateMachines::InvalidTransition, ActiveRecord::StaleObjectError rescue StateMachines::InvalidTransition, ActiveRecord::StaleObjectError
# We are looping to find another build that is not conflicting # We are looping to find another build that is not conflicting
...@@ -72,6 +66,24 @@ module Ci ...@@ -72,6 +66,24 @@ module Ci
private private
def assign_runner!(build, params)
build.runner_id = runner.id
build.runner_session_attributes = params[:session] if params[:session].present?
unless build.valid_build_dependencies?
build.drop!(:missing_dependency_failure)
return false
end
unless build.supported_runner?(params.dig(:info, :features))
build.drop!(:runner_unsupported)
return false
end
build.run!
return true
end
def builds_for_shared_runner def builds_for_shared_runner
new_builds. new_builds.
# don't run projects which have not enabled shared runners and builds # don't run projects which have not enabled shared runners and builds
......
...@@ -80,7 +80,15 @@ module API ...@@ -80,7 +80,15 @@ module API
params do params do
requires :token, type: String, desc: %q(Runner's authentication token) requires :token, type: String, desc: %q(Runner's authentication token)
optional :last_update, type: String, desc: %q(Runner's queue last_update token) optional :last_update, type: String, desc: %q(Runner's queue last_update token)
optional :info, type: Hash, desc: %q(Runner's metadata) optional :info, type: Hash, desc: %q(Runner's metadata) do
optional :name, type: String, desc: %q(Runner's name)
optional :version, type: String, desc: %q(Runner's version)
optional :revision, type: String, desc: %q(Runner's revision)
optional :platform, type: String, desc: %q(Runner's platform)
optional :architecture, type: String, desc: %q(Runner's architecture)
optional :executor, type: String, desc: %q(Runner's executor)
optional :features, type: Hash, desc: %q(Runner's features)
end
optional :session, type: Hash, desc: %q(Runner's session data) do optional :session, type: Hash, desc: %q(Runner's session data) do
optional :url, type: String, desc: %q(Session's url) optional :url, type: String, desc: %q(Session's url)
optional :certificate, type: String, desc: %q(Session's certificate) optional :certificate, type: String, desc: %q(Session's certificate)
......
...@@ -9,7 +9,8 @@ module Gitlab ...@@ -9,7 +9,8 @@ module Gitlab
'api_failure' => 'API failure', 'api_failure' => 'API failure',
'stuck_or_timeout_failure' => 'stuck or timeout failure', 'stuck_or_timeout_failure' => 'stuck or timeout failure',
'runner_system_failure' => 'runner system failure', 'runner_system_failure' => 'runner system failure',
'missing_dependency_failure' => 'missing dependency failure' 'missing_dependency_failure' => 'missing dependency failure',
# COMMENTED to check if CI fails: 'runner_unsupported' => 'unsuported runner',
}.freeze }.freeze
def status_tooltip def status_tooltip
......
...@@ -231,7 +231,7 @@ describe Ci::BuildPresenter do ...@@ -231,7 +231,7 @@ describe Ci::BuildPresenter do
let(:build) { create(:ci_build, :failed, :script_failure) } let(:build) { create(:ci_build, :failed, :script_failure) }
context 'when is a script or missing dependency failure' do context 'when is a script or missing dependency failure' do
let(:failure_reasons) { %w(script_failure missing_dependency_failure) } let(:failure_reasons) { %w(script_failure missing_dependency_failure runner_unsupported) }
it 'should return false' do it 'should return false' do
failure_reasons.each do |failure_reason| failure_reasons.each do |failure_reason|
......
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