Class: Ci::Bridge
Constant Summary
collapse
- InvalidBridgeTypeError =
Class.new(StandardError)
- InvalidTransitionError =
Class.new(StandardError)
- FORWARD_DEFAULTS =
{
yaml_variables: true,
pipeline_variables: false
}.freeze
TaggableQueries::MAX_TAGS_IDS, TaggableQueries::TooManyTagsError
Constants included
from HasStatus
HasStatus::ACTIVE_STATUSES, HasStatus::ALIVE_STATUSES, HasStatus::AVAILABLE_STATUSES, HasStatus::BLOCKED_STATUS, HasStatus::CANCELABLE_STATUSES, HasStatus::COMPLETED_STATUSES, HasStatus::DEFAULT_STATUS, HasStatus::EXCLUDE_IGNORED_STATUSES, HasStatus::ORDERED_STATUSES, HasStatus::PASSED_WITH_WARNINGS_STATUSES, HasStatus::STARTED_STATUSES, HasStatus::STATUSES_ENUM, HasStatus::STOPPED_STATUSES, HasStatus::UnknownStatusError
ApplicationRecord::MAX_PLUCK
Instance Attribute Summary
Attributes included from Importable
#imported, #importing
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from HasRef
#branch?, #git_ref, #ref_slug
#run_after_commit, #run_after_commit_or_now
#cancel_gracefully?, #degenerate!, #degenerated?, #ensure_metadata, #has_exposed_artifacts?, #interruptible, #interruptible=, #options, #options=, #yaml_variables, #yaml_variables=
#scoped_variables, #simple_variables, #simple_variables_without_dependencies, #track_duration
Methods inherited from Processable
#aggregated_needs_names, #all_dependencies, #all_met_to_become_pending?, #clone, #dependency_variables, #ensure_scheduling_type!, #find_legacy_scheduling_type, #needs_attributes, populate_scheduling_type!, #scheduling_type_dag?, select_with_aggregated_needs, #when, #with_resource_group?
#extended, extensions, #included, #method_added, #override, #prepended, #queue_verification, verify!
#clear_memoization, #strong_memoize, #strong_memoized?
#all_met_to_become_pending?, #archived?, #auto_canceled?, bulk_insert_tags!, #cancelable?, #duration, #expire_etag_cache!, #failed_but_allowed?, #group_name, #has_trace?, #importing?, #latest?, #locking_enabled?, locking_enabled?, names, #queued_duration, #recoverable?, #sortable_name, #stuck?, update_as_processed!, #update_older_statuses_retried!
#tags_ids
#bulk_insert_associations!, bulk_inserts_enabled?, with_bulk_insert
#present
Methods included from HasStatus
#active?, #blocked?, #complete?, #started?
model_name, table_name_prefix
cached_column_list, #create_or_load_association, declarative_enum, default_select_columns, id_in, id_not_in, iid_in, pluck_primary_key, primary_key_in, #readable_by?, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, #to_ability_name, underscore, where_exists, where_not_exists, with_fast_read_statement_timeout, without_order
#serializable_hash
Class Method Details
.clone_accessors ⇒ Object
76
77
78
79
80
81
|
# File 'app/models/ci/bridge.rb', line 76
def self.clone_accessors
%i[pipeline project ref tag options name
allow_failure stage stage_id stage_idx
yaml_variables when description needs_attributes
scheduling_type].freeze
end
|
.with_preloads ⇒ Object
68
69
70
71
72
73
74
|
# File 'app/models/ci/bridge.rb', line 68
def self.with_preloads
preload(
:metadata,
downstream_pipeline: [project: [:route, { namespace: :route }]],
project: [:namespace]
)
end
|
Instance Method Details
#action? ⇒ Boolean
155
156
157
|
# File 'app/models/ci/bridge.rb', line 155
def action?
%w[manual].include?(self.when)
end
|
#any_unmet_prerequisites? ⇒ Boolean
177
178
179
|
# File 'app/models/ci/bridge.rb', line 177
def any_unmet_prerequisites?
false
end
|
#artifacts? ⇒ Boolean
rubocop: enable CodeReuse/ServiceClass
169
170
171
|
# File 'app/models/ci/bridge.rb', line 169
def artifacts?
false
end
|
#dependent? ⇒ Boolean
211
212
213
214
215
|
# File 'app/models/ci/bridge.rb', line 211
def dependent?
strong_memoize(:dependent) do
options&.dig(:trigger, :strategy) == 'depend'
end
end
|
#detailed_status(current_user) ⇒ Object
141
142
143
144
145
|
# File 'app/models/ci/bridge.rb', line 141
def detailed_status(current_user)
Gitlab::Ci::Status::Bridge::Factory
.new(self, current_user)
.fabricate!
end
|
#downstream_pipeline_params ⇒ Object
98
99
100
101
102
103
|
# File 'app/models/ci/bridge.rb', line 98
def downstream_pipeline_params
return child_params if triggers_child_pipeline?
return cross_project_params if downstream_project.present?
{}
end
|
#downstream_project ⇒ Object
105
106
107
108
109
110
111
112
113
|
# File 'app/models/ci/bridge.rb', line 105
def downstream_project
strong_memoize(:downstream_project) do
if downstream_project_path
::Project.find_by_full_path(downstream_project_path)
elsif triggers_child_pipeline?
project
end
end
end
|
#downstream_project_path ⇒ Object
115
116
117
118
119
|
# File 'app/models/ci/bridge.rb', line 115
def downstream_project_path
strong_memoize(:downstream_project_path) do
options&.dig(:trigger, :project)
end
end
|
#downstream_variables ⇒ Object
217
218
219
220
221
222
223
224
225
226
|
# File 'app/models/ci/bridge.rb', line 217
def downstream_variables
if ::Feature.enabled?(:ci_trigger_forward_variables, project)
calculate_downstream_variables
.reverse .uniq { |var| var[:key] } .reverse
else
legacy_downstream_variables
end
end
|
#execute_hooks ⇒ Object
187
188
189
|
# File 'app/models/ci/bridge.rb', line 187
def execute_hooks
raise NotImplementedError
end
|
#expanded_environment_name ⇒ Object
181
182
|
# File 'app/models/ci/bridge.rb', line 181
def expanded_environment_name
end
|
#has_downstream_pipeline? ⇒ Boolean
94
95
96
|
# File 'app/models/ci/bridge.rb', line 94
def has_downstream_pipeline?
sourced_pipelines.exists?
end
|
#inherit_status_from_downstream!(pipeline) ⇒ Object
83
84
85
86
87
88
89
90
91
92
|
# File 'app/models/ci/bridge.rb', line 83
def inherit_status_from_downstream!(pipeline)
case pipeline.status
when 'success'
self.success!
when 'failed', 'canceled', 'skipped'
self.drop!
else
false
end
end
|
#parent_pipeline ⇒ Object
121
122
123
|
# File 'app/models/ci/bridge.rb', line 121
def parent_pipeline
pipeline if triggers_child_pipeline?
end
|
#persisted_environment ⇒ Object
184
185
|
# File 'app/models/ci/bridge.rb', line 184
def persisted_environment
end
|
#play(current_user, job_variables_attributes = nil) ⇒ Object
rubocop: disable CodeReuse/ServiceClass We don't need it but we are taking `job_variables_attributes` parameter to make it consistent with `Ci::Build#play` method.
162
163
164
165
166
|
# File 'app/models/ci/bridge.rb', line 162
def play(current_user, job_variables_attributes = nil)
Ci::PlayBridgeService
.new(project, current_user)
.execute(self)
end
|
#playable? ⇒ Boolean
151
152
153
|
# File 'app/models/ci/bridge.rb', line 151
def playable?
action? && !archived? && manual?
end
|
#retryable? ⇒ Boolean
60
61
62
63
64
65
66
|
# File 'app/models/ci/bridge.rb', line 60
def retryable?
return false unless Feature.enabled?(:ci_recreate_downstream_pipeline, project)
return false if failed? && (pipeline_loop_detected? || reached_max_descendant_pipelines_depth?)
super
end
|
#runnable? ⇒ Boolean
173
174
175
|
# File 'app/models/ci/bridge.rb', line 173
def runnable?
false
end
|
#schedulable? ⇒ Boolean
147
148
149
|
# File 'app/models/ci/bridge.rb', line 147
def schedulable?
false
end
|
137
138
139
|
# File 'app/models/ci/bridge.rb', line 137
def tags
[:bridge]
end
|
#target_ref ⇒ Object
202
203
204
205
206
207
208
209
|
# File 'app/models/ci/bridge.rb', line 202
def target_ref
branch = options&.dig(:trigger, :branch)
return unless branch
scoped_variables.to_runner_variables.yield_self do |all_variables|
::ExpandVariables.expand(branch, all_variables)
end
end
|
#target_revision_ref ⇒ Object
228
229
230
|
# File 'app/models/ci/bridge.rb', line 228
def target_revision_ref
downstream_pipeline_params.dig(:target_revision, :ref)
end
|
#to_partial_path ⇒ Object
191
192
193
|
# File 'app/models/ci/bridge.rb', line 191
def to_partial_path
'projects/generic_commit_statuses/generic_commit_status'
end
|
#triggers_child_pipeline? ⇒ Boolean
129
130
131
|
# File 'app/models/ci/bridge.rb', line 129
def triggers_child_pipeline?
yaml_for_downstream.present?
end
|
#triggers_cross_project_pipeline? ⇒ Boolean
133
134
135
|
# File 'app/models/ci/bridge.rb', line 133
def triggers_cross_project_pipeline?
downstream_project_path.present?
end
|
#triggers_downstream_pipeline? ⇒ Boolean
125
126
127
|
# File 'app/models/ci/bridge.rb', line 125
def triggers_downstream_pipeline?
triggers_child_pipeline? || triggers_cross_project_pipeline?
end
|
#yaml_for_downstream ⇒ Object
195
196
197
198
199
200
|
# File 'app/models/ci/bridge.rb', line 195
def yaml_for_downstream
strong_memoize(:yaml_for_downstream) do
includes = options&.dig(:trigger, :include)
YAML.dump('include' => includes) if includes
end
end
|