summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShinya Maeda <shinya@gitlab.com>2017-08-30 17:11:13 +0900
committerShinya Maeda <shinya@gitlab.com>2017-08-30 17:11:13 +0900
commit4d0f9c9e2802e96a4dd908a87edffd4f317fc507 (patch)
treedb560cb061f9cc49042d76c629fc4e7494004b1d
parent6f0f65becbbe968bd26a5a3872044d7b8633bf2e (diff)
downloadgitlab-ce-feature/sm/34834-missing-dependency-should-fail-job.tar.gz
Missing dependency should fail jobfeature/sm/34834-missing-dependency-should-fail-job
-rw-r--r--app/models/ci/build.rb10
-rw-r--r--app/services/ci/register_job_service.rb8
2 files changed, 17 insertions, 1 deletions
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb
index 095192e9894..6d57cc9d2c7 100644
--- a/app/models/ci/build.rb
+++ b/app/models/ci/build.rb
@@ -437,6 +437,16 @@ module Ci
options[:dependencies]&.empty?
end
+ def dependencies_exist_in_previous_stage?
+ return true if empty_dependencies?
+
+ depended_jobs = depends_on_builds
+
+ depended_jobs.select do |job|
+ options[:dependencies].include?(job.name)
+ end.any?
+ end
+
def hide_secrets(trace)
return unless trace
diff --git a/app/services/ci/register_job_service.rb b/app/services/ci/register_job_service.rb
index 414f672cc6a..c4da4426708 100644
--- a/app/services/ci/register_job_service.rb
+++ b/app/services/ci/register_job_service.rb
@@ -3,6 +3,7 @@ module Ci
# proper pending build to runner on runner API request
class RegisterJobService
include Gitlab::CurrentSettings
+ class MissingDependenciesError < StandardError; end
attr_reader :runner
@@ -26,6 +27,11 @@ module Ci
next unless runner.can_pick?(build)
begin
+ if build.dependencies_exist_in_previous_stage?
+ build.drop!
+ raise MissingDependenciesError.new
+ end
+
# 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.
build.runner_id = runner.id
@@ -33,7 +39,7 @@ module Ci
register_success(build)
return Result.new(build, true)
- rescue StateMachines::InvalidTransition, ActiveRecord::StaleObjectError
+ rescue StateMachines::InvalidTransition, ActiveRecord::StaleObjectError, MissingDependenciesError
# We are looping to find another build that is not conflicting
# It also indicates that this build can be picked and passed to runner.
# If we don't do it, basically a bunch of runners would be competing for a build