Class: Gitlab::Ci::Pipeline::Chain::Command

Inherits:
Struct
  • Object
show all
Includes:
Utils::StrongMemoize
Defined in:
lib/gitlab/ci/pipeline/chain/command.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#after_shaObject

Returns the value of attribute after_sha

Returns:

  • (Object)

    the current value of after_sha



7
8
9
# File 'lib/gitlab/ci/pipeline/chain/command.rb', line 7

def after_sha
  @after_sha
end

#before_shaObject

Returns the value of attribute before_sha

Returns:

  • (Object)

    the current value of before_sha



7
8
9
# File 'lib/gitlab/ci/pipeline/chain/command.rb', line 7

def before_sha
  @before_sha
end

#bridgeObject

Returns the value of attribute bridge

Returns:

  • (Object)

    the current value of bridge



7
8
9
# File 'lib/gitlab/ci/pipeline/chain/command.rb', line 7

def bridge
  @bridge
end

#chat_dataObject

Returns the value of attribute chat_data

Returns:

  • (Object)

    the current value of chat_data



7
8
9
# File 'lib/gitlab/ci/pipeline/chain/command.rb', line 7

def chat_data
  @chat_data
end

#checkout_shaObject

Returns the value of attribute checkout_sha

Returns:

  • (Object)

    the current value of checkout_sha



7
8
9
# File 'lib/gitlab/ci/pipeline/chain/command.rb', line 7

def checkout_sha
  @checkout_sha
end

#config_contentObject

Returns the value of attribute config_content

Returns:

  • (Object)

    the current value of config_content



7
8
9
# File 'lib/gitlab/ci/pipeline/chain/command.rb', line 7

def config_content
  @config_content
end

#contentObject

Returns the value of attribute content

Returns:

  • (Object)

    the current value of content



7
8
9
# File 'lib/gitlab/ci/pipeline/chain/command.rb', line 7

def content
  @content
end

#current_userObject

Returns the value of attribute current_user

Returns:

  • (Object)

    the current value of current_user



7
8
9
# File 'lib/gitlab/ci/pipeline/chain/command.rb', line 7

def current_user
  @current_user
end

#dry_runObject

Returns the value of attribute dry_run

Returns:

  • (Object)

    the current value of dry_run



7
8
9
# File 'lib/gitlab/ci/pipeline/chain/command.rb', line 7

def dry_run
  @dry_run
end

#external_pull_requestObject

Returns the value of attribute external_pull_request

Returns:

  • (Object)

    the current value of external_pull_request



7
8
9
# File 'lib/gitlab/ci/pipeline/chain/command.rb', line 7

def external_pull_request
  @external_pull_request
end

#gitaly_contextObject

Returns the value of attribute gitaly_context

Returns:

  • (Object)

    the current value of gitaly_context



7
8
9
# File 'lib/gitlab/ci/pipeline/chain/command.rb', line 7

def gitaly_context
  @gitaly_context
end

#ignore_skip_ciObject

Returns the value of attribute ignore_skip_ci

Returns:

  • (Object)

    the current value of ignore_skip_ci



7
8
9
# File 'lib/gitlab/ci/pipeline/chain/command.rb', line 7

def ignore_skip_ci
  @ignore_skip_ci
end

#inputsObject

Returns the value of attribute inputs

Returns:

  • (Object)

    the current value of inputs



7
8
9
# File 'lib/gitlab/ci/pipeline/chain/command.rb', line 7

def inputs
  @inputs
end

#lintingObject

Returns the value of attribute linting

Returns:

  • (Object)

    the current value of linting



7
8
9
# File 'lib/gitlab/ci/pipeline/chain/command.rb', line 7

def linting
  @linting
end

#loggerObject

Returns the value of attribute logger

Returns:

  • (Object)

    the current value of logger



7
8
9
# File 'lib/gitlab/ci/pipeline/chain/command.rb', line 7

def logger
  @logger
end

#merge_requestObject

Returns the value of attribute merge_request

Returns:

  • (Object)

    the current value of merge_request



7
8
9
# File 'lib/gitlab/ci/pipeline/chain/command.rb', line 7

def merge_request
  @merge_request
end

#mirror_updateObject

Returns the value of attribute mirror_update

Returns:

  • (Object)

    the current value of mirror_update



7
8
9
# File 'lib/gitlab/ci/pipeline/chain/command.rb', line 7

def mirror_update
  @mirror_update
end

#origin_refObject

Returns the value of attribute origin_ref

Returns:

  • (Object)

    the current value of origin_ref



7
8
9
# File 'lib/gitlab/ci/pipeline/chain/command.rb', line 7

def origin_ref
  @origin_ref
end

#partition_idObject

Returns the value of attribute partition_id

Returns:

  • (Object)

    the current value of partition_id



7
8
9
# File 'lib/gitlab/ci/pipeline/chain/command.rb', line 7

def partition_id
  @partition_id
end

#pipeline_configObject

Returns the value of attribute pipeline_config

Returns:

  • (Object)

    the current value of pipeline_config



7
8
9
# File 'lib/gitlab/ci/pipeline/chain/command.rb', line 7

def pipeline_config
  @pipeline_config
end

#pipeline_creation_forced_to_continueObject

Returns the value of attribute pipeline_creation_forced_to_continue

Returns:

  • (Object)

    the current value of pipeline_creation_forced_to_continue



7
8
9
# File 'lib/gitlab/ci/pipeline/chain/command.rb', line 7

def pipeline_creation_forced_to_continue
  @pipeline_creation_forced_to_continue
end

#pipeline_policy_contextObject

Returns the value of attribute pipeline_policy_context

Returns:

  • (Object)

    the current value of pipeline_policy_context



7
8
9
# File 'lib/gitlab/ci/pipeline/chain/command.rb', line 7

def pipeline_policy_context
  @pipeline_policy_context
end

#pipeline_seedObject

Returns the value of attribute pipeline_seed

Returns:

  • (Object)

    the current value of pipeline_seed



7
8
9
# File 'lib/gitlab/ci/pipeline/chain/command.rb', line 7

def pipeline_seed
  @pipeline_seed
end

#projectObject

Returns the value of attribute project

Returns:

  • (Object)

    the current value of project



7
8
9
# File 'lib/gitlab/ci/pipeline/chain/command.rb', line 7

def project
  @project
end

#push_optionsObject

Returns the value of attribute push_options

Returns:

  • (Object)

    the current value of push_options



7
8
9
# File 'lib/gitlab/ci/pipeline/chain/command.rb', line 7

def push_options
  @push_options
end

#save_incompletedObject

Returns the value of attribute save_incompleted

Returns:

  • (Object)

    the current value of save_incompleted



7
8
9
# File 'lib/gitlab/ci/pipeline/chain/command.rb', line 7

def save_incompleted
  @save_incompleted
end

#scheduleObject

Returns the value of attribute schedule

Returns:

  • (Object)

    the current value of schedule



7
8
9
# File 'lib/gitlab/ci/pipeline/chain/command.rb', line 7

def schedule
  @schedule
end

#seeds_blockObject

Returns the value of attribute seeds_block

Returns:

  • (Object)

    the current value of seeds_block



7
8
9
# File 'lib/gitlab/ci/pipeline/chain/command.rb', line 7

def seeds_block
  @seeds_block
end

#sourceObject

Returns the value of attribute source

Returns:

  • (Object)

    the current value of source



7
8
9
# File 'lib/gitlab/ci/pipeline/chain/command.rb', line 7

def source
  @source
end

#source_shaObject

Returns the value of attribute source_sha

Returns:

  • (Object)

    the current value of source_sha



7
8
9
# File 'lib/gitlab/ci/pipeline/chain/command.rb', line 7

def source_sha
  @source_sha
end

#target_shaObject

Returns the value of attribute target_sha

Returns:

  • (Object)

    the current value of target_sha



7
8
9
# File 'lib/gitlab/ci/pipeline/chain/command.rb', line 7

def target_sha
  @target_sha
end

#variables_attributesObject

Returns the value of attribute variables_attributes

Returns:

  • (Object)

    the current value of variables_attributes



7
8
9
# File 'lib/gitlab/ci/pipeline/chain/command.rb', line 7

def variables_attributes
  @variables_attributes
end

#workflow_rules_resultObject

Returns the value of attribute workflow_rules_result

Returns:

  • (Object)

    the current value of workflow_rules_result



7
8
9
# File 'lib/gitlab/ci/pipeline/chain/command.rb', line 7

def workflow_rules_result
  @workflow_rules_result
end

#yaml_processor_resultObject

Returns the value of attribute yaml_processor_result

Returns:

  • (Object)

    the current value of yaml_processor_result



7
8
9
# File 'lib/gitlab/ci/pipeline/chain/command.rb', line 7

def yaml_processor_result
  @yaml_processor_result
end

Instance Method Details

#ambiguous_ref?Boolean

Returns:

  • (Boolean)


79
80
81
82
83
# File 'lib/gitlab/ci/pipeline/chain/command.rb', line 79

def ambiguous_ref?
  strong_memoize(:ambiguous_ref) do
    project.repository.ambiguous_ref?(origin_ref)
  end
end

#branch_exists?Boolean

Returns:

  • (Boolean)


33
34
35
36
37
# File 'lib/gitlab/ci/pipeline/chain/command.rb', line 33

def branch_exists?
  strong_memoize(:is_branch) do
    branch_ref? && project.repository.branch_exists?(ref)
  end
end

#creates_child_pipeline?Boolean

Returns:

  • (Boolean)


93
94
95
# File 'lib/gitlab/ci/pipeline/chain/command.rb', line 93

def creates_child_pipeline?
  bridge&.triggers_child_pipeline?
end

#current_pipeline_sizeObject



105
106
107
108
109
110
111
112
# File 'lib/gitlab/ci/pipeline/chain/command.rb', line 105

def current_pipeline_size
  # The `pipeline_seed` attribute is assigned after the Seed step.
  # And, the seed is populated when calling the `pipeline_seed.stages` method in Populate.
  # So, there is no guarantee that `pipeline_seed` will return a meaningful result.
  # If it does not, it's not important, we can just return 0.
  # This is also the reason why we don't "strong memoize" this method.
  pipeline_seed&.size || 0
end

#dry_run?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/gitlab/ci/pipeline/chain/command.rb', line 25

def dry_run?
  dry_run
end

#increment_pipeline_failure_reason_counter(reason) ⇒ Object



148
149
150
151
# File 'lib/gitlab/ci/pipeline/chain/command.rb', line 148

def increment_pipeline_failure_reason_counter(reason)
  metrics.pipeline_failure_reason_counter
    .increment(reason: (reason || :unknown_failure).to_s)
end

#jobs_count_in_alive_pipelinesObject



114
115
116
# File 'lib/gitlab/ci/pipeline/chain/command.rb', line 114

def jobs_count_in_alive_pipelines
  project.all_pipelines.jobs_count_in_alive_pipelines
end

#linting?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/gitlab/ci/pipeline/chain/command.rb', line 29

def linting?
  linting
end

#merge_request_ref_exists?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/gitlab/ci/pipeline/chain/command.rb', line 45

def merge_request_ref_exists?
  check_merge_request_ref
end

#metricsObject



97
98
99
# File 'lib/gitlab/ci/pipeline/chain/command.rb', line 97

def metrics
  @metrics ||= ::Gitlab::Ci::Pipeline::Metrics
end

#observe_creation_duration(duration) ⇒ Object



129
130
131
132
133
134
# File 'lib/gitlab/ci/pipeline/chain/command.rb', line 129

def observe_creation_duration(duration)
  logger.observe(:pipeline_creation_duration_s, duration, once: true)

  metrics.pipeline_creation_duration_histogram
    .observe({ gitlab: gitlab_org_project?.to_s }, duration.seconds)
end

#observe_jobs_count_in_alive_pipelinesObject



143
144
145
146
# File 'lib/gitlab/ci/pipeline/chain/command.rb', line 143

def observe_jobs_count_in_alive_pipelines
  metrics.active_jobs_histogram
    .observe({ plan: project.actual_plan_name }, jobs_count_in_alive_pipelines + current_pipeline_size)
end

#observe_pipeline_size(pipeline) ⇒ Object



136
137
138
139
140
141
# File 'lib/gitlab/ci/pipeline/chain/command.rb', line 136

def observe_pipeline_size(pipeline)
  logger.observe(:pipeline_size_count, pipeline.total_size, once: true)

  metrics.pipeline_size_histogram
    .observe({ source: pipeline.source.to_s, plan: project.actual_plan_name }, pipeline.total_size)
end

#observe_step_duration(step_class, duration) ⇒ Object



119
120
121
122
123
124
125
126
127
# File 'lib/gitlab/ci/pipeline/chain/command.rb', line 119

def observe_step_duration(step_class, duration)
  step = step_class.name.underscore.parameterize(separator: '_')
  logger.observe("pipeline_step_#{step}_duration_s", duration, once: true)

  if Feature.enabled?(:ci_pipeline_creation_step_duration_tracking, type: :ops)
    metrics.pipeline_creation_step_duration_histogram
      .observe({ step: step_class.name }, duration.seconds)
  end
end

#origin_shaObject



65
66
67
# File 'lib/gitlab/ci/pipeline/chain/command.rb', line 65

def origin_sha
  checkout_sha || after_sha
end

#parent_pipelineObject



85
86
87
# File 'lib/gitlab/ci/pipeline/chain/command.rb', line 85

def parent_pipeline
  bridge&.parent_pipeline
end

#parent_pipeline_partition_idObject



89
90
91
# File 'lib/gitlab/ci/pipeline/chain/command.rb', line 89

def parent_pipeline_partition_id
  parent_pipeline.partition_id if creates_child_pipeline?
end

#protected_ref?Boolean

Returns:

  • (Boolean)


73
74
75
76
77
# File 'lib/gitlab/ci/pipeline/chain/command.rb', line 73

def protected_ref?
  strong_memoize(:protected_ref) do
    project.protected_for?(origin_ref)
  end
end

#readonly?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/gitlab/ci/pipeline/chain/command.rb', line 21

def readonly?
  dry_run? || linting?
end

#refObject



53
54
55
56
57
# File 'lib/gitlab/ci/pipeline/chain/command.rb', line 53

def ref
  strong_memoize(:ref) do
    Gitlab::Git.ref_name(origin_ref)
  end
end

#shaObject



59
60
61
62
63
# File 'lib/gitlab/ci/pipeline/chain/command.rb', line 59

def sha
  strong_memoize(:sha) do
    project.commit(origin_sha || origin_ref).try(:id)
  end
end

#tag_exists?Boolean

Returns:

  • (Boolean)


39
40
41
42
43
# File 'lib/gitlab/ci/pipeline/chain/command.rb', line 39

def tag_exists?
  strong_memoize(:is_tag) do
    tag_ref? && project.repository.tag_exists?(ref)
  end
end

#workload_ref_exists?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/gitlab/ci/pipeline/chain/command.rb', line 49

def workload_ref_exists?
  ::Ci::Workloads::Workload.workload_ref?(origin_ref) && project.repository.ref_exists?(origin_ref)
end