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

Constructor Details

#initialize(params = {}) ⇒ Command

Returns a new instance of Command.



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

def initialize(params = {})
  params.each do |key, value|
    self[key] = value
  end
end

Instance Attribute Details

#after_shaObject

Returns the value of attribute after_sha

Returns:

  • (Object)

    the current value of after_sha



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

def after_sha
  @after_sha
end

#allow_mirror_updateObject

Returns the value of attribute allow_mirror_update

Returns:

  • (Object)

    the current value of allow_mirror_update



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

def allow_mirror_update
  @allow_mirror_update
end

#before_shaObject

Returns the value of attribute before_sha

Returns:

  • (Object)

    the current value of before_sha



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

def before_sha
  @before_sha
end

#bridgeObject

Returns the value of attribute bridge

Returns:

  • (Object)

    the current value of bridge



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

def bridge
  @bridge
end

#chat_dataObject

Returns the value of attribute chat_data

Returns:

  • (Object)

    the current value of chat_data



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

def chat_data
  @chat_data
end

#checkout_shaObject

Returns the value of attribute checkout_sha

Returns:

  • (Object)

    the current value of checkout_sha



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

def checkout_sha
  @checkout_sha
end

#config_contentObject

Returns the value of attribute config_content

Returns:

  • (Object)

    the current value of config_content



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

def config_content
  @config_content
end

#contentObject

Returns the value of attribute content

Returns:

  • (Object)

    the current value of content



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

def content
  @content
end

#current_userObject

Returns the value of attribute current_user

Returns:

  • (Object)

    the current value of current_user



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

def current_user
  @current_user
end

#dry_runObject Also known as: dry_run?

Returns the value of attribute dry_run

Returns:

  • (Object)

    the current value of dry_run



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

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



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

def external_pull_request
  @external_pull_request
end

#ignore_skip_ciObject

Returns the value of attribute ignore_skip_ci

Returns:

  • (Object)

    the current value of ignore_skip_ci



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

def ignore_skip_ci
  @ignore_skip_ci
end

#loggerObject

Returns the value of attribute logger

Returns:

  • (Object)

    the current value of logger



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

def logger
  @logger
end

#merge_requestObject

Returns the value of attribute merge_request

Returns:

  • (Object)

    the current value of merge_request



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

def merge_request
  @merge_request
end

#origin_refObject

Returns the value of attribute origin_ref

Returns:

  • (Object)

    the current value of origin_ref



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

def origin_ref
  @origin_ref
end

#pipeline_configObject

Returns the value of attribute pipeline_config

Returns:

  • (Object)

    the current value of pipeline_config



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

def pipeline_config
  @pipeline_config
end

#pipeline_seedObject

Returns the value of attribute pipeline_seed

Returns:

  • (Object)

    the current value of pipeline_seed



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

def pipeline_seed
  @pipeline_seed
end

#projectObject

Returns the value of attribute project

Returns:

  • (Object)

    the current value of project



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

def project
  @project
end

#push_optionsObject

Returns the value of attribute push_options

Returns:

  • (Object)

    the current value of push_options



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

def push_options
  @push_options
end

#save_incompletedObject

Returns the value of attribute save_incompleted

Returns:

  • (Object)

    the current value of save_incompleted



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

def save_incompleted
  @save_incompleted
end

#scheduleObject

Returns the value of attribute schedule

Returns:

  • (Object)

    the current value of schedule



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

def schedule
  @schedule
end

#seeds_blockObject

Returns the value of attribute seeds_block

Returns:

  • (Object)

    the current value of seeds_block



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

def seeds_block
  @seeds_block
end

#sourceObject

Returns the value of attribute source

Returns:

  • (Object)

    the current value of source



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

def source
  @source
end

#source_shaObject

Returns the value of attribute source_sha

Returns:

  • (Object)

    the current value of source_sha



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

def source_sha
  @source_sha
end

#target_shaObject

Returns the value of attribute target_sha

Returns:

  • (Object)

    the current value of target_sha



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

def target_sha
  @target_sha
end

#trigger_requestObject

Returns the value of attribute trigger_request

Returns:

  • (Object)

    the current value of trigger_request



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

def trigger_request
  @trigger_request
end

#variables_attributesObject

Returns the value of attribute variables_attributes

Returns:

  • (Object)

    the current value of variables_attributes



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

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



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

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



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

def yaml_processor_result
  @yaml_processor_result
end

Instance Method Details

#ambiguous_ref?Boolean

Returns:

  • (Boolean)


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

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

#branch_exists?Boolean

Returns:

  • (Boolean)


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

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

#creates_child_pipeline?Boolean

Returns:

  • (Boolean)


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

def creates_child_pipeline?
  bridge&.triggers_child_pipeline?
end

#increment_pipeline_failure_reason_counter(reason) ⇒ Object



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

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

#merge_request_ref_exists?Boolean

Returns:

  • (Boolean)


41
42
43
44
45
46
# File 'lib/gitlab/ci/pipeline/chain/command.rb', line 41

def merge_request_ref_exists?
  strong_memoize(:merge_request_ref_exists) do
    MergeRequest.merge_request_ref?(origin_ref) &&
      project.repository.ref_exists?(origin_ref)
  end
end

#metricsObject



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

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

#observe_creation_duration(duration) ⇒ Object



110
111
112
113
114
115
# File 'lib/gitlab/ci/pipeline/chain/command.rb', line 110

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



124
125
126
127
128
129
# File 'lib/gitlab/ci/pipeline/chain/command.rb', line 124

def observe_jobs_count_in_alive_pipelines
  jobs_count = project.all_pipelines.jobs_count_in_alive_pipelines

  metrics.active_jobs_histogram
    .observe({ plan: project.actual_plan_name }, jobs_count)
end

#observe_pipeline_size(pipeline) ⇒ Object



117
118
119
120
121
122
# File 'lib/gitlab/ci/pipeline/chain/command.rb', line 117

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



100
101
102
103
104
105
106
107
108
# File 'lib/gitlab/ci/pipeline/chain/command.rb', line 100

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



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

def origin_sha
  checkout_sha || after_sha
end

#parent_pipelineObject



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

def parent_pipeline
  bridge&.parent_pipeline
end

#parent_pipeline_partition_idObject



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

def parent_pipeline_partition_id
  parent_pipeline.partition_id if creates_child_pipeline?
end

#protected_ref?Boolean

Returns:

  • (Boolean)


68
69
70
71
72
# File 'lib/gitlab/ci/pipeline/chain/command.rb', line 68

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

#refObject



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

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

#shaObject



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

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

#tag_exists?Boolean

Returns:

  • (Boolean)


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

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