Module: Ci::Contextable

Included in:
Bridge, Build
Defined in:
app/models/concerns/ci/contextable.rb

Overview

This module implements methods that provide context in form of essential CI/CD variables that can be used by a build / bridge job.

Instance Method Summary collapse

Instance Method Details

#scoped_variables(environment: expanded_environment_name, dependencies: true) ⇒ Object

Variables in the environment name scope.


12
13
14
15
16
17
18
# File 'app/models/concerns/ci/contextable.rb', line 12

def scoped_variables(environment: expanded_environment_name, dependencies: true)
  track_duration do
    pipeline
      .variables_builder
      .scoped_variables(self, environment: environment, dependencies: dependencies)
  end
end

#simple_variablesObject

Variables that do not depend on the environment name.


35
36
37
38
39
# File 'app/models/concerns/ci/contextable.rb', line 35

def simple_variables
  strong_memoize(:simple_variables) do
    scoped_variables(environment: nil)
  end
end

#simple_variables_without_dependenciesObject


41
42
43
44
45
# File 'app/models/concerns/ci/contextable.rb', line 41

def simple_variables_without_dependencies
  strong_memoize(:variables_without_dependencies) do
    scoped_variables(environment: nil, dependencies: false)
  end
end

#track_durationObject


20
21
22
23
24
25
26
27
28
29
30
# File 'app/models/concerns/ci/contextable.rb', line 20

def track_duration
  start_time = ::Gitlab::Metrics::System.monotonic_time
  result = yield
  duration = ::Gitlab::Metrics::System.monotonic_time - start_time

  ::Gitlab::Ci::Pipeline::Metrics
    .pipeline_builder_scoped_variables_histogram
    .observe({}, duration.seconds)

  result
end