d8670e114a
* master: (198 commits) Set inverse_of for Project/Services relation Fix admin hooks spec Prevent default disabled buttons and links. Add index on `requested_at` to the `members` table Rearrange order of tabs Fix admin active tab tests Show created_at in table column Nest li elements directly under ul Move builds tab to admin overview Add monitoring link with subtabs Add sub links to overview Add counter for abuse reports Remove admin layout-nav counters Move admin nav to horizontal layout nav Eager load project relations in IssueParser Use validate and required for environment and project Award Emoji can't be awarded on system notes backend Get rid of Gitlab::ShellEnv Update CHANGELOG. Fix project star tooltip on the fly. ... Conflicts: app/services/ci/create_builds_service.rb
56 lines
1.8 KiB
Ruby
56 lines
1.8 KiB
Ruby
module Ci
|
|
class CreateBuildsService
|
|
def initialize(pipeline)
|
|
@pipeline = pipeline
|
|
@config = pipeline.config_processor
|
|
end
|
|
|
|
def execute(stage, user, status, trigger_request = nil)
|
|
builds_attrs = @config.builds_for_stage_and_ref(stage, @pipeline.ref, @pipeline.tag, trigger_request)
|
|
|
|
# check when to create next build
|
|
builds_attrs = builds_attrs.select do |build_attrs|
|
|
case build_attrs[:when]
|
|
when 'on_success'
|
|
status == 'success'
|
|
when 'on_failure'
|
|
status == 'failed'
|
|
when 'always'
|
|
%w(success failed).include?(status)
|
|
end
|
|
end
|
|
|
|
# don't create the same build twice
|
|
builds_attrs.reject! do |build_attrs|
|
|
@pipeline.builds.find_by(ref: @pipeline.ref,
|
|
tag: @pipeline.tag,
|
|
trigger_request: trigger_request,
|
|
name: build_attrs[:name])
|
|
end
|
|
|
|
builds_attrs.map do |build_attrs|
|
|
build_attrs.slice!(:name,
|
|
:commands,
|
|
:tag_list,
|
|
:options,
|
|
:allow_failure,
|
|
:stage,
|
|
:stage_idx,
|
|
:environment)
|
|
|
|
build_attrs.merge!(pipeline: @pipeline,
|
|
ref: @pipeline.ref,
|
|
tag: @pipeline.tag,
|
|
trigger_request: trigger_request,
|
|
user: user,
|
|
project: @pipeline.project)
|
|
|
|
##
|
|
# We do not persist new builds here.
|
|
# Those will be persisted when @pipeline is saved.
|
|
#
|
|
@pipeline.builds.new(build_attrs)
|
|
end
|
|
end
|
|
end
|
|
end
|