Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ensure_environments.rb « chain « pipeline « ci « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 245ef32f06b8dc84eeb78674381e6a2f63f15f6e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# frozen_string_literal: true

module Gitlab
  module Ci
    module Pipeline
      module Chain
        class EnsureEnvironments < Chain::Base
          def perform!
            pipeline.stages.map(&:statuses).flatten.each(&method(:ensure_environment))
          end

          def break?
            false
          end

          private

          def ensure_environment(build)
            return unless build.instance_of?(::Ci::Build) && build.has_environment?

            environment = ::Gitlab::Ci::Pipeline::Seed::Environment.new(build).to_resource

            if environment.persisted?
              build.persisted_environment = environment
              build.assign_attributes(metadata_attributes: { expanded_environment_name: environment.name })
            else
              build.assign_attributes(status: :failed, failure_reason: :environment_creation_failure)
            end
          end
        end
      end
    end
  end
end