Class: Ci::Bridge
Constant Summary
collapse
- InvalidBridgeTypeError =
Class.new(StandardError)
- InvalidTransitionError =
Class.new(StandardError)
- FORWARD_DEFAULTS =
{
yaml_variables: true,
pipeline_variables: false
}.freeze
Constants inherited
from Processable
Processable::ACTIONABLE_WHEN
Constants included
from HasStatus
HasStatus::ACTIVE_STATUSES, HasStatus::ALIVE_STATUSES, HasStatus::AVAILABLE_STATUSES, HasStatus::BLOCKED_STATUS, HasStatus::CANCELABLE_STATUSES, HasStatus::COMPLETED_STATUSES, HasStatus::COMPLETED_WITH_MANUAL_STATUSES, HasStatus::DEFAULT_STATUS, HasStatus::EXECUTING_STATUSES, HasStatus::IGNORED_STATUSES, HasStatus::ORDERED_STATUSES, HasStatus::PASSED_WITH_WARNINGS_STATUSES, HasStatus::STARTED_STATUSES, HasStatus::STATUSES_ENUM, HasStatus::STOPPED_STATUSES, HasStatus::UnknownStatusError
ApplicationRecord::MAX_PLUCK
HasCheckConstraints::NOT_NULL_CHECK_PATTERN
ResetOnColumnErrors::MAX_RESET_PERIOD
Instance Attribute Summary
Attributes included from Importable
#importing, #user_contributions
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from HasRef
#branch?, #git_ref, #ref_slug, #workload?
#run_after_commit, #run_after_commit_or_now
Methods included from Deployable
#accesses_environment?, #actual_persisted_environment, #deployment_job?, #deployment_status, #environment_action, #environment_auto_stop_in, #environment_options_for_permanent_storage, #environment_permanent_metadata, #environment_slug, #environment_status, #environment_tier, #environment_url, #expanded_auto_stop_in, #expanded_deployment_tier, #expanded_environment_name, #expanded_kubernetes_namespace, #has_environment_keyword?, #has_outdated_deployment?, #link_to_environment, #on_stop, #persisted_environment, #persisted_environment=, #prepares_environment?, #stop_action_successful?, #stops_environment?, #successful_deployment_status, #verifies_environment?
#manual_variables, #scoped_variables, #simple_variables, #simple_variables_without_dependencies, #track_duration, #unprotected_scoped_variables
Methods inherited from Processable
#aggregated_needs_names, #all_dependencies, #all_met_to_become_pending?, #archived?, #assign_resource_from_resource_group, #dependency_variables, #enqueue_immediately?, #ensure_scheduling_type!, #expanded_environment_name, fabricate, #find_legacy_scheduling_type, #job_dependencies_with_accessible_artifacts, #manual_confirmation_message, #manual_job?, #needs_attributes, #other_manual_actions, #persisted_environment, populate_scheduling_type!, #redis_state, #scheduling_type_dag?, #scoped_user, select_with_aggregated_needs, #set_enqueue_immediately!, #source, #when, #with_resource_group?
#extended, extensions, #included, #method_added, #override, #prepended, #queue_verification, verify!
#artifacts_exposed_as, #artifacts_exposed_paths, #debug_trace_enabled?, #degenerate!, #degenerated?, #downstream_errors, #enable_debug_trace!, #exit_code, #exit_code=, #has_exposed_artifacts?, #id_tokens, #id_tokens=, #id_tokens?, #interruptible, #interruptible=, #options, #options=, #scoped_user_id, #secrets=, #timeout_human_readable_value, #timeout_source_value, #timeout_value, #update_timeout_state, #yaml_variables, #yaml_variables=
#all_met_to_become_pending?, #archived?, #auto_canceled?, #cancelable?, #duration, #exit_code=, #expire_etag_cache!, #force_cancelable?, #group_name, #has_trace?, #latest?, #locking_enabled?, locking_enabled?, names, #queued_duration, #recoverable?, #resource_parent, #sortable_name, #stage_name, #stuck?, #supports_canceling?, #supports_force_cancel?, #test_suite_name, #to_ability_name, update_as_processed!, #update_older_statuses_retried!
#bulk_insert_associations!, bulk_inserts_enabled?, with_bulk_insert
#present
Methods included from HasStatus
#active?, #blocked?, #complete?, #complete_or_manual?, #incomplete?, #started?
registered_models
model_name, table_name_prefix
===, cached_column_list, #create_or_load_association, current_transaction, declarative_enum, default_select_columns, delete_all_returning, #deleted_from_database?, id_in, id_not_in, iid_in, nullable_column?, 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
#sharding_organization
#reset_on_union_error, #reset_on_unknown_attribute_error
#serializable_hash
Class Method Details
.clone_accessors ⇒ Object
103
104
105
106
107
|
# File 'app/models/ci/bridge.rb', line 103
def self.clone_accessors
i[pipeline project ref tag name allow_failure stage_idx
when environment description needs_attributes
scheduling_type ci_stage partition_id resource_group].freeze
end
|
.with_preloads ⇒ Object
92
93
94
95
96
97
98
99
100
101
|
# File 'app/models/ci/bridge.rb', line 92
def self.with_preloads
preload(
:metadata,
:job_definition,
:error_job_messages,
user: [:followers, :followees],
downstream_pipeline: [project: [:route, { namespace: :route }]],
project: [:namespace]
)
end
|
Instance Method Details
#action? ⇒ Boolean
181
182
183
|
# File 'app/models/ci/bridge.rb', line 181
def action?
%w[manual].include?(self.when)
end
|
#any_unmet_prerequisites? ⇒ Boolean
219
220
221
|
# File 'app/models/ci/bridge.rb', line 219
def any_unmet_prerequisites?
false
end
|
#artifacts? ⇒ Boolean
211
212
213
|
# File 'app/models/ci/bridge.rb', line 211
def artifacts?
false
end
|
#artifacts_expire_at ⇒ Object
203
|
# File 'app/models/ci/bridge.rb', line 203
def artifacts_expire_at; end
|
#can_auto_cancel_pipeline_on_job_failure? ⇒ Boolean
185
186
187
|
# File 'app/models/ci/bridge.rb', line 185
def can_auto_cancel_pipeline_on_job_failure?
true
end
|
#dependent? ⇒ Boolean
257
258
259
260
261
|
# File 'app/models/ci/bridge.rb', line 257
def dependent?
strong_memoize(:dependent) do
options&.dig(:trigger, :strategy) == 'depend'
end
end
|
#detailed_status(current_user) ⇒ Object
167
168
169
170
171
|
# File 'app/models/ci/bridge.rb', line 167
def detailed_status(current_user)
Gitlab::Ci::Status::Bridge::Factory
.new(self, current_user)
.fabricate!
end
|
#downstream_pipeline_params ⇒ Object
119
120
121
122
123
124
|
# File 'app/models/ci/bridge.rb', line 119
def downstream_pipeline_params
return child_params if triggers_child_pipeline?
return cross_project_params if downstream_project.present?
{}
end
|
#downstream_project ⇒ Object
126
127
128
129
130
131
132
133
134
|
# File 'app/models/ci/bridge.rb', line 126
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
136
137
138
139
140
141
142
143
144
145
|
# File 'app/models/ci/bridge.rb', line 136
def downstream_project_path
strong_memoize(:downstream_project_path) do
project = options&.dig(:trigger, :project)
next unless project
scoped_variables.to_hash_variables.then do |all_variables|
::ExpandVariables.expand(project, all_variables)
end
end
end
|
#downstream_variables ⇒ Object
267
268
269
|
# File 'app/models/ci/bridge.rb', line 267
def downstream_variables
Gitlab::Ci::Variables::Downstream::Generator.new(self).calculate
end
|
#execute_hooks ⇒ Object
223
224
225
|
# File 'app/models/ci/bridge.rb', line 223
def execute_hooks
raise NotImplementedError
end
|
#forward_pipeline_variables? ⇒ Boolean
308
309
310
311
312
313
314
|
# File 'app/models/ci/bridge.rb', line 308
def forward_pipeline_variables?
strong_memoize(:forward_pipeline_variables) do
result = options&.dig(:trigger, :forward, :pipeline_variables)
result.nil? ? FORWARD_DEFAULTS[:pipeline_variables] : result
end
end
|
#forward_yaml_variables? ⇒ Boolean
300
301
302
303
304
305
306
|
# File 'app/models/ci/bridge.rb', line 300
def forward_yaml_variables?
strong_memoize(:forward_yaml_variables) do
result = options&.dig(:trigger, :forward, :yaml_variables)
result.nil? ? FORWARD_DEFAULTS[:yaml_variables] : result
end
end
|
#has_downstream_pipeline? ⇒ Boolean
115
116
117
|
# File 'app/models/ci/bridge.rb', line 115
def has_downstream_pipeline?
sourced_pipeline.present?
end
|
#has_strategy? ⇒ Boolean
247
248
249
|
# File 'app/models/ci/bridge.rb', line 247
def has_strategy?
mirrored? || dependent?
end
|
#inherit_status_from_downstream(pipeline) ⇒ Object
316
317
318
319
320
321
322
|
# File 'app/models/ci/bridge.rb', line 316
def inherit_status_from_downstream(pipeline)
if mirrored?
inherit_mirrored_status_from_downstream!(pipeline)
else
inherit_dependent_status_from_downstream!(pipeline)
end
end
|
#job_artifacts ⇒ Object
rubocop: enable CodeReuse/ServiceClass
199
200
201
|
# File 'app/models/ci/bridge.rb', line 199
def job_artifacts
Ci::JobArtifact.none
end
|
#mirrored? ⇒ Boolean
251
252
253
254
255
|
# File 'app/models/ci/bridge.rb', line 251
def mirrored?
strong_memoize(:mirrored) do
options&.dig(:trigger, :strategy) == 'mirror'
end
end
|
#parent_pipeline ⇒ Object
147
148
149
|
# File 'app/models/ci/bridge.rb', line 147
def parent_pipeline
pipeline if triggers_child_pipeline?
end
|
#pipeline_schedule_variables ⇒ Object
294
295
296
297
298
|
# File 'app/models/ci/bridge.rb', line 294
def pipeline_schedule_variables
return [] unless pipeline.pipeline_schedule
pipeline.pipeline_schedule.variables.to_a
end
|
#pipeline_variables ⇒ Object
290
291
292
|
# File 'app/models/ci/bridge.rb', line 290
def pipeline_variables
pipeline.variables
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.
192
193
194
195
196
|
# File 'app/models/ci/bridge.rb', line 192
def play(current_user, job_variables_attributes = nil)
Ci::PlayBridgeService
.new(project, current_user)
.execute(self)
end
|
#playable? ⇒ Boolean
177
178
179
|
# File 'app/models/ci/bridge.rb', line 177
def playable?
action? && !archived? && manual?
end
|
#retryable? ⇒ Boolean
109
110
111
112
113
|
# File 'app/models/ci/bridge.rb', line 109
def retryable?
return false if failed? && (pipeline_loop_detected? || reached_max_descendant_pipelines_depth?)
super
end
|
#runnable? ⇒ Boolean
215
216
217
|
# File 'app/models/ci/bridge.rb', line 215
def runnable?
false
end
|
#runner ⇒ Object
205
|
# File 'app/models/ci/bridge.rb', line 205
def runner; end
|
#schedulable? ⇒ Boolean
173
174
175
|
# File 'app/models/ci/bridge.rb', line 173
def schedulable?
false
end
|
#tag_list ⇒ Object
207
208
209
|
# File 'app/models/ci/bridge.rb', line 207
def tag_list
Gitlab::Ci::Tags::TagList.new
end
|
163
164
165
|
# File 'app/models/ci/bridge.rb', line 163
def tags
[:bridge]
end
|
#target_ref ⇒ Object
238
239
240
241
242
243
244
245
|
# File 'app/models/ci/bridge.rb', line 238
def target_ref
branch = options&.dig(:trigger, :branch)
return unless branch
scoped_variables.to_hash_variables.then do |all_variables|
::ExpandVariables.expand(branch, all_variables)
end
end
|
#target_revision_ref ⇒ Object
263
264
265
|
# File 'app/models/ci/bridge.rb', line 263
def target_revision_ref
downstream_pipeline_params.dig(:target_revision, :ref)
end
|
#to_partial_path ⇒ Object
227
228
229
|
# File 'app/models/ci/bridge.rb', line 227
def to_partial_path
'projects/generic_commit_statuses/generic_commit_status'
end
|
#triggers_child_pipeline? ⇒ Boolean
155
156
157
|
# File 'app/models/ci/bridge.rb', line 155
def triggers_child_pipeline?
yaml_for_downstream.present?
end
|
#triggers_cross_project_pipeline? ⇒ Boolean
159
160
161
|
# File 'app/models/ci/bridge.rb', line 159
def triggers_cross_project_pipeline?
downstream_project_path.present?
end
|
#triggers_downstream_pipeline? ⇒ Boolean
151
152
153
|
# File 'app/models/ci/bridge.rb', line 151
def triggers_downstream_pipeline?
triggers_child_pipeline? || triggers_cross_project_pipeline?
end
|
#variables ⇒ Object
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
|
# File 'app/models/ci/bridge.rb', line 271
def variables
strong_memoize(:variables) do
bridge_variables =
if ::Feature.disabled?(:exclude_protected_variables_from_multi_project_pipeline_triggers, project) ||
(expose_protected_project_variables? && expose_protected_group_variables?)
scoped_variables
else
unprotected_scoped_variables(
expose_project_variables: expose_protected_project_variables?,
expose_group_variables: expose_protected_group_variables?
)
end
Gitlab::Ci::Variables::Collection.new
.concat(bridge_variables)
.concat(pipeline.persisted_variables)
end
end
|
#yaml_for_downstream ⇒ Object
231
232
233
234
235
236
|
# File 'app/models/ci/bridge.rb', line 231
def yaml_for_downstream
strong_memoize(:yaml_for_downstream) do
includes = options&.dig(:trigger, :include)
YAML.dump('include' => includes) if includes
end
end
|