debian-mirror-gitlab/app/models/concerns/ci/contextable.rb

89 lines
2.9 KiB
Ruby
Raw Normal View History

2019-07-07 11:18:12 +05:30
# frozen_string_literal: true
module Ci
##
# This module implements methods that provide context in form of
# essential CI/CD variables that can be used by a build / bridge job.
#
module Contextable
##
# Variables in the environment name scope.
#
2020-10-24 23:57:45 +05:30
def scoped_variables(environment: expanded_environment_name, dependencies: true)
2021-12-11 22:18:48 +05:30
track_duration do
variables = pipeline.variables_builder.scoped_variables(self, environment: environment, dependencies: dependencies)
2022-03-02 08:16:31 +05:30
next variables if pipeline.use_variables_builder_definitions?
2019-07-07 11:18:12 +05:30
variables.concat(project.predefined_variables)
variables.concat(pipeline.predefined_variables)
variables.concat(runner.predefined_variables) if runnable? && runner
2021-12-11 22:18:48 +05:30
variables.concat(kubernetes_variables)
2020-01-01 13:55:28 +05:30
variables.concat(deployment_variables(environment: environment))
2019-07-07 11:18:12 +05:30
variables.concat(yaml_variables)
variables.concat(user_variables)
2020-10-24 23:57:45 +05:30
variables.concat(dependency_variables) if dependencies
2020-05-24 23:13:21 +05:30
variables.concat(secret_instance_variables)
2021-04-17 20:07:23 +05:30
variables.concat(secret_group_variables(environment: environment))
2019-07-07 11:18:12 +05:30
variables.concat(secret_project_variables(environment: environment))
variables.concat(trigger_request.user_variables) if trigger_request
variables.concat(pipeline.variables)
variables.concat(pipeline.pipeline_schedule.job_variables) if pipeline.pipeline_schedule
2021-12-11 22:18:48 +05:30
variables
2019-07-07 11:18:12 +05:30
end
end
2021-12-11 22:18:48 +05:30
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
2019-07-07 11:18:12 +05:30
##
# Variables that do not depend on the environment name.
#
def simple_variables
strong_memoize(:simple_variables) do
2021-11-11 11:23:49 +05:30
scoped_variables(environment: nil)
2019-07-07 11:18:12 +05:30
end
end
2020-10-24 23:57:45 +05:30
def simple_variables_without_dependencies
strong_memoize(:variables_without_dependencies) do
2021-11-11 11:23:49 +05:30
scoped_variables(environment: nil, dependencies: false)
2020-10-24 23:57:45 +05:30
end
end
2019-07-07 11:18:12 +05:30
def user_variables
2022-03-02 08:16:31 +05:30
pipeline.variables_builder.user_variables(user)
2019-07-07 11:18:12 +05:30
end
2021-12-11 22:18:48 +05:30
def kubernetes_variables
2022-03-02 08:16:31 +05:30
pipeline.variables_builder.kubernetes_variables(self)
2021-12-11 22:18:48 +05:30
end
2020-01-01 13:55:28 +05:30
def deployment_variables(environment:)
2022-03-02 08:16:31 +05:30
pipeline.variables_builder.deployment_variables(job: self, environment: environment)
2020-01-01 13:55:28 +05:30
end
2020-05-24 23:13:21 +05:30
def secret_instance_variables
2022-03-02 08:16:31 +05:30
pipeline.variables_builder.secret_instance_variables(ref: git_ref)
2020-05-24 23:13:21 +05:30
end
2021-04-17 20:07:23 +05:30
def secret_group_variables(environment: expanded_environment_name)
2022-03-02 08:16:31 +05:30
pipeline.variables_builder.secret_group_variables(environment: environment, ref: git_ref)
2019-07-07 11:18:12 +05:30
end
2021-04-17 20:07:23 +05:30
def secret_project_variables(environment: expanded_environment_name)
2022-03-02 08:16:31 +05:30
pipeline.variables_builder.secret_project_variables(environment: environment, ref: git_ref)
2019-07-07 11:18:12 +05:30
end
end
end