summaryrefslogtreecommitdiff
path: root/lib/gitlab
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-03-04 00:07:52 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-03-04 00:07:52 +0000
commit4fe93274dec62ff7361a67be88e320131d66b788 (patch)
tree98ae79e3101ffd6569fc48bb4c7ad8808540ceb8 /lib/gitlab
parentbbaf2bb0438b1c71020d9d216feb528add225a7f (diff)
downloadgitlab-ce-4fe93274dec62ff7361a67be88e320131d66b788.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab')
-rw-r--r--lib/gitlab/ci/pipeline/seed/build.rb33
-rw-r--r--lib/gitlab/ci/pipeline/seed/deployment.rb6
-rw-r--r--lib/gitlab/ci/pipeline/seed/environment.rb14
3 files changed, 35 insertions, 18 deletions
diff --git a/lib/gitlab/ci/pipeline/seed/build.rb b/lib/gitlab/ci/pipeline/seed/build.rb
index 98b4b4593e0..114a46ca9f6 100644
--- a/lib/gitlab/ci/pipeline/seed/build.rb
+++ b/lib/gitlab/ci/pipeline/seed/build.rb
@@ -7,6 +7,8 @@ module Gitlab
class Build < Seed::Base
include Gitlab::Utils::StrongMemoize
+ EnvironmentCreationFailure = Class.new(StandardError)
+
delegate :dig, to: :@seed_attributes
# When the `ci_dag_limit_needs` is enabled it uses the lower limit
@@ -77,14 +79,39 @@ module Gitlab
if bridge?
::Ci::Bridge.new(attributes)
else
- ::Ci::Build.new(attributes).tap do |job|
- job.deployment = Seed::Deployment.new(job).to_resource
- job.resource_group = Seed::Build::ResourceGroup.new(job, @resource_group_key).to_resource
+ ::Ci::Build.new(attributes).tap do |build|
+ build.assign_attributes(self.class.environment_attributes_for(build))
+ build.resource_group = Seed::Build::ResourceGroup.new(build, @resource_group_key).to_resource
end
end
end
end
+ def self.environment_attributes_for(build)
+ return {} unless build.has_environment?
+
+ environment = Seed::Environment.new(build).to_resource
+
+ # If there is a validation error on environment creation, such as
+ # the name contains invalid character, the build falls back to a
+ # non-environment job.
+ unless environment.persisted?
+ Gitlab::ErrorTracking.track_exception(
+ EnvironmentCreationFailure.new,
+ project_id: build.project_id,
+ reason: environment.errors.full_messages.to_sentence)
+
+ return { environment: nil }
+ end
+
+ {
+ deployment: Seed::Deployment.new(build, environment).to_resource,
+ metadata_attributes: {
+ expanded_environment_name: environment.name
+ }
+ }
+ end
+
private
def all_of_only?
diff --git a/lib/gitlab/ci/pipeline/seed/deployment.rb b/lib/gitlab/ci/pipeline/seed/deployment.rb
index cc63fb4c609..624189acc8a 100644
--- a/lib/gitlab/ci/pipeline/seed/deployment.rb
+++ b/lib/gitlab/ci/pipeline/seed/deployment.rb
@@ -7,9 +7,9 @@ module Gitlab
class Deployment < Seed::Base
attr_reader :job, :environment
- def initialize(job)
+ def initialize(job, environment)
@job = job
- @environment = Seed::Environment.new(@job)
+ @environment = environment
end
def to_resource
@@ -17,7 +17,6 @@ module Gitlab
return unless job.starts_environment?
deployment = ::Deployment.new(attributes)
- deployment.environment = environment.to_resource
# If there is a validation error on environment creation, such as
# the name contains invalid character, the job will fall back to a
@@ -45,6 +44,7 @@ module Gitlab
def attributes
{
project: job.project,
+ environment: environment,
user: job.user,
ref: job.ref,
tag: job.tag,
diff --git a/lib/gitlab/ci/pipeline/seed/environment.rb b/lib/gitlab/ci/pipeline/seed/environment.rb
index 2d3a1e702f9..42e8c365824 100644
--- a/lib/gitlab/ci/pipeline/seed/environment.rb
+++ b/lib/gitlab/ci/pipeline/seed/environment.rb
@@ -12,25 +12,15 @@ module Gitlab
end
def to_resource
- find_environment || ::Environment.create(attributes)
+ job.project.environments
+ .safe_find_or_create_by(name: expanded_environment_name)
end
private
- def find_environment
- job.project.environments.find_by_name(expanded_environment_name)
- end
-
def expanded_environment_name
job.expanded_environment_name
end
-
- def attributes
- {
- project: job.project,
- name: expanded_environment_name
- }
- end
end
end
end