summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2018-03-21 10:01:37 +0100
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2018-03-21 10:01:37 +0100
commit3145cbaaa0b8d267f91bf26b52ca28b21f225745 (patch)
tree1cbcdbbee0cd9529500e8fa2855641e2be6baa20
parentad61a1815400e8c9fce1758618379874d93868e6 (diff)
downloadgitlab-ce-3145cbaaa0b8d267f91bf26b52ca28b21f225745.tar.gz
Decouple pipeline stage seeds from building environments
-rw-r--r--app/services/ci/create_pipeline_stages_service.rb12
-rw-r--r--lib/gitlab/ci/pipeline/chain/create.rb13
-rw-r--r--lib/gitlab/ci/pipeline/seed/stage.rb8
-rw-r--r--lib/gitlab/ci/yaml_processor.rb6
4 files changed, 21 insertions, 18 deletions
diff --git a/app/services/ci/create_pipeline_stages_service.rb b/app/services/ci/create_pipeline_stages_service.rb
index f2c175adee6..5c3530393f7 100644
--- a/app/services/ci/create_pipeline_stages_service.rb
+++ b/app/services/ci/create_pipeline_stages_service.rb
@@ -3,17 +3,7 @@ module Ci
def execute(pipeline)
pipeline.stage_seeds.each do |seed|
seed.user = current_user
-
- seed.create! do |build|
- ##
- # Create the environment before the build starts. This sets its slug and
- # makes it available as an environment variable
- #
- if build.has_environment?
- environment_name = build.expanded_environment_name
- project.environments.find_or_create_by(name: environment_name)
- end
- end
+ seed.create!
end
end
end
diff --git a/lib/gitlab/ci/pipeline/chain/create.rb b/lib/gitlab/ci/pipeline/chain/create.rb
index d5e17a123df..9f5c141ad14 100644
--- a/lib/gitlab/ci/pipeline/chain/create.rb
+++ b/lib/gitlab/ci/pipeline/chain/create.rb
@@ -14,6 +14,19 @@ module Gitlab
::Ci::CreatePipelineStagesService
.new(project, current_user)
.execute(pipeline)
+
+ # TODO populate environments with find_or_initialize_by in the chain too.
+
+ ##
+ # Create the environment before the build starts. This sets its slug and
+ # makes it available as an environment variable
+ #
+ pipeline.builds.each do |build|
+ if build.has_environment?
+ environment_name = build.expanded_environment_name
+ project.environments.find_or_create_by(name: environment_name)
+ end
+ end
end
rescue ActiveRecord::RecordInvalid => e
error("Failed to persist the pipeline: #{e}")
diff --git a/lib/gitlab/ci/pipeline/seed/stage.rb b/lib/gitlab/ci/pipeline/seed/stage.rb
index 3e5abf8c02b..3a532e09909 100644
--- a/lib/gitlab/ci/pipeline/seed/stage.rb
+++ b/lib/gitlab/ci/pipeline/seed/stage.rb
@@ -19,7 +19,9 @@ module Gitlab
end
def attributes
- { name: @name, pipeline: @pipeline, project: @pipeline.project }
+ { name: @name,
+ pipeline: @pipeline,
+ project: @pipeline.project }
end
# TODO decouple
@@ -43,10 +45,6 @@ module Gitlab
@pipeline.stages << stage
stage.save!
-
- stage.builds.each do |build|
- yield build if block_given?
- end
end
end
end
diff --git a/lib/gitlab/ci/yaml_processor.rb b/lib/gitlab/ci/yaml_processor.rb
index 60bd3b0d1b7..70ed20d6913 100644
--- a/lib/gitlab/ci/yaml_processor.rb
+++ b/lib/gitlab/ci/yaml_processor.rb
@@ -73,8 +73,10 @@ module Gitlab
seeds = @stages.uniq.map do |stage|
builds = pipeline_stage_builds(stage, pipeline)
- Gitlab::Ci::Pipeline::Seed::Stage
- .new(pipeline, stage, builds) if builds.any?
+ if builds.any?
+ Gitlab::Ci::Pipeline::Seed::Stage
+ .new(pipeline, stage, builds)
+ end
end
seeds.compact