build.rb 19.3 KB
Newer Older
D
Douwe Maan 已提交
1
module Ci
K
Kamil Trzcinski 已提交
2
  class Build < CommitStatus
Z
Zeger-Jan van de Weg 已提交
3
    prepend ArtifactMigratable
4
    include TokenAuthenticatable
5
    include AfterCommitQueue
6
    include ObjectStorage::BackgroundMove
R
Rémy Coutable 已提交
7
    include Presentable
S
Shinya Maeda 已提交
8
    include Importable
9

10 11
    MissingDependenciesError = Class.new(StandardError)

12
    belongs_to :project, inverse_of: :builds
13 14
    belongs_to :runner
    belongs_to :trigger_request
15
    belongs_to :erased_by, class_name: 'User'
D
Douwe Maan 已提交
16

17
    has_many :deployments, as: :deployable
18

19
    has_one :last_deployment, -> { order('deployments.id DESC') }, as: :deployable, class_name: 'Deployment'
20
    has_many :trace_sections, class_name: 'Ci::BuildTraceSection'
21

Z
Zeger-Jan van de Weg 已提交
22
    has_many :job_artifacts, class_name: 'Ci::JobArtifact', foreign_key: :job_id, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent
23 24
    has_one :job_artifacts_archive, -> { where(file_type: Ci::JobArtifact.file_types[:archive]) }, class_name: 'Ci::JobArtifact', inverse_of: :job, foreign_key: :job_id
    has_one :job_artifacts_metadata, -> { where(file_type: Ci::JobArtifact.file_types[:metadata]) }, class_name: 'Ci::JobArtifact', inverse_of: :job, foreign_key: :job_id
S
Shinya Maeda 已提交
25
    has_one :job_artifacts_trace, -> { where(file_type: Ci::JobArtifact.file_types[:trace]) }, class_name: 'Ci::JobArtifact', inverse_of: :job, foreign_key: :job_id
26

27
    has_one :metadata, class_name: 'Ci::BuildMetadata'
T
Tomasz Maczukin 已提交
28 29
    delegate :timeout, to: :metadata, prefix: true, allow_nil: true

30 31 32
    ##
    # The "environment" field for builds is a String, and is the unexpanded name!
    #
33 34 35
    def persisted_environment
      @persisted_environment ||= Environment.find_by(
        name: expanded_environment_name,
K
Kamil Trzciński 已提交
36
        project: project
37 38 39
      )
    end

40 41
    serialize :options # rubocop:disable Cop/ActiveRecordSerialize
    serialize :yaml_variables, Gitlab::Serializer::Ci::Variables # rubocop:disable Cop/ActiveRecordSerialize
D
Douwe Maan 已提交
42

D
Douwe Maan 已提交
43 44
    delegate :name, to: :project, prefix: true

D
Douwe Maan 已提交
45
    validates :coverage, numericality: true, allow_blank: true
D
Douwe Maan 已提交
46
    validates :ref, presence: true
D
Douwe Maan 已提交
47 48

    scope :unstarted, ->() { where(runner_id: nil) }
K
Kamil Trzcinski 已提交
49
    scope :ignore_failures, ->() { where(allow_failure: false) }
50
    scope :with_artifacts_archive, ->() do
51
      where('(artifacts_file IS NOT NULL AND artifacts_file <> ?) OR EXISTS (?)',
52
        '', Ci::JobArtifact.select(1).where('ci_builds.id = ci_job_artifacts.job_id').archive)
53
    end
54
    scope :with_artifacts_stored_locally, -> { with_artifacts_archive.where(artifacts_file_store: [nil, LegacyArtifactUploader::Store::LOCAL]) }
55 56
    scope :with_artifacts_not_expired, ->() { with_artifacts_archive.where('artifacts_expire_at IS NULL OR artifacts_expire_at > ?', Time.now) }
    scope :with_expired_artifacts, ->() { with_artifacts_archive.where('artifacts_expire_at < ?', Time.now) }
57
    scope :last_month, ->() { where('created_at > ?', Date.today - 1.month) }
58
    scope :manual_actions, ->() { where(when: :manual, status: COMPLETED_STATUSES + [:manual]) }
59
    scope :ref_protected, -> { where(protected: true) }
60

61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
    scope :matches_tag_ids, -> (tag_ids) do
      matcher = ::ActsAsTaggableOn::Tagging
        .where(taggable_type: CommitStatus)
        .where(context: 'tags')
        .where('taggable_id = ci_builds.id')
        .where.not(tag_id: tag_ids).select('1')

      where("NOT EXISTS (?)", matcher)
    end

    scope :with_any_tags, -> do
      matcher = ::ActsAsTaggableOn::Tagging
        .where(taggable_type: CommitStatus)
        .where(context: 'tags')
        .where('taggable_id = ci_builds.id').select('1')

      where("EXISTS (?)", matcher)
    end

80 81
    mount_uploader :legacy_artifacts_file, LegacyArtifactUploader, mount_on: :artifacts_file
    mount_uploader :legacy_artifacts_metadata, LegacyArtifactUploader, mount_on: :artifacts_metadata
K
Kamil Trzcinski 已提交
82

D
Douwe Maan 已提交
83 84
    acts_as_taggable

85 86
    add_authentication_token_field :token

L
Lin Jen-Shin 已提交
87
    before_save :update_artifacts_size, if: :artifacts_file_changed?
88
    before_save :ensure_token
89
    before_destroy { unscoped_project }
G
Grzegorz Bizon 已提交
90

91
    after_create unless: :importing? do |build|
92
      run_after_commit { BuildHooksWorker.perform_async(build.id) }
93 94
    end

95 96
    after_commit :update_project_statistics_after_save, on: [:create, :update]
    after_commit :update_project_statistics, on: :destroy
D
Douwe Maan 已提交
97 98

    class << self
99 100 101 102 103 104
      # This is needed for url_for to work,
      # as the controller is JobsController
      def model_name
        ActiveModel::Name.new(self, nil, 'job')
      end

D
Douwe Maan 已提交
105 106 107 108
      def first_pending
        pending.unstarted.order('created_at ASC').first
      end

109
      def retry(build, current_user)
110 111 112
        Ci::RetryBuildService
          .new(build.project, current_user)
          .execute(build)
D
Douwe Maan 已提交
113 114 115
      end
    end

116
    state_machine :status do
117 118
      event :actionize do
        transition created: :manual
K
Kamil Trzcinski 已提交
119 120
      end

121 122
      after_transition any => [:pending] do |build|
        build.run_after_commit do
K
linting  
Kim "BKC" Carlbäcker 已提交
123
          BuildQueueWorker.perform_async(id)
124 125 126
        end
      end

127
      after_transition pending: :running do |build|
128 129 130
        build.run_after_commit do
          BuildHooksWorker.perform_async(id)
        end
131 132
      end

133
      after_transition any => [:success, :failed, :canceled] do |build|
134
        build.run_after_commit do
135
          BuildFinishedWorker.perform_async(id)
136
        end
D
Douwe Maan 已提交
137
      end
138

139
      after_transition any => [:success] do |build|
140 141
        build.run_after_commit do
          BuildSuccessWorker.perform_async(id)
142 143
        end
      end
144

145
      before_transition any => [:failed] do |build|
146
        next unless build.project
147
        next if build.retries_max.zero?
148

149
        if build.retries_count < build.retries_max
150 151 152 153 154
          begin
            Ci::Build.retry(build, build.user)
          rescue Gitlab::Access::AccessDeniedError => ex
            Rails.logger.error "Unable to auto-retry job #{build.id}: #{ex}"
          end
155 156
        end
      end
157 158

      before_transition any => [:running] do |build|
159
        build.validates_dependencies! unless Feature.enabled?('ci_disable_validates_dependencies')
160
      end
T
Tomasz Maczukin 已提交
161 162

      before_transition pending: :running do |build|
163
        build.ensure_metadata.update_timeout_state
T
Tomasz Maczukin 已提交
164
      end
D
Douwe Maan 已提交
165 166
    end

167
    def ensure_metadata
T
Tomasz Maczukin 已提交
168
      metadata || build_metadata(project: project)
D
Douwe Maan 已提交
169 170
    end

171
    def detailed_status(current_user)
172 173 174
      Gitlab::Ci::Status::Build::Factory
        .new(self, current_user)
        .fabricate!
K
Kamil Trzcinski 已提交
175 176
    end

177
    def other_actions
178
      pipeline.manual_actions.where.not(name: name)
179 180
    end

181
    def playable?
182
      action? && (manual? || complete?)
K
Kamil Trzcinski 已提交
183 184
    end

185
    def action?
186 187 188
      self.when == 'manual'
    end

189
    def play(current_user)
190 191 192
      Ci::PlayBuildService
        .new(project, current_user)
        .execute(self)
193 194
    end

K
Kamil Trzcinski 已提交
195 196 197 198
    def cancelable?
      active?
    end

K
Kamil Trzcinski 已提交
199
    def retryable?
200
      success? || failed? || canceled?
K
Kamil Trzcinski 已提交
201
    end
202 203 204 205 206 207 208 209

    def retries_count
      pipeline.builds.retried.where(name: self.name).count
    end

    def retries_max
      self.options.fetch(:retry, 0).to_i
    end
K
Kamil Trzcinski 已提交
210

211 212
    def latest?
      !retried?
K
Kamil Trzcinski 已提交
213 214
    end

215
    def expanded_environment_name
216 217 218
      if has_environment?
        ExpandVariables.expand(environment, simple_variables)
      end
219 220
    end

221
    def has_environment?
222
      environment.present?
223 224
    end

225
    def starts_environment?
226
      has_environment? && self.environment_action == 'start'
227 228 229
    end

    def stops_environment?
230
      has_environment? && self.environment_action == 'stop'
231 232 233
    end

    def environment_action
234
      self.options.fetch(:environment, {}).fetch(:action, 'start') if self.options
235 236 237 238
    end

    def outdated_deployment?
      success? && !last_deployment.try(:last?)
239
    end
240

241 242
    def depends_on_builds
      # Get builds of the same type
243
      latest_builds = self.pipeline.builds.latest
244 245 246 247 248

      # Return builds from previous stages
      latest_builds.where('stage_idx < ?', stage_idx)
    end

249
    def triggered_by?(current_user)
S
Shinya Maeda 已提交
250 251 252
      user == current_user
    end

N
Nick Thomas 已提交
253 254 255 256 257 258
    # A slugified version of the build ref, suitable for inclusion in URLs and
    # domain names. Rules:
    #
    #   * Lowercased
    #   * Anything not matching [a-z0-9-] is replaced with a -
    #   * Maximum length is 63 bytes
S
Shinya Maeda 已提交
259
    #   * First/Last Character is not a hyphen
N
Nick Thomas 已提交
260
    def ref_slug
V
vanadium23 已提交
261
      Gitlab::Utils.slugify(ref.to_s)
N
Nick Thomas 已提交
262 263
    end

264
    ##
265
    # Variables in the environment name scope.
266
    #
267 268
    def scoped_variables(environment: expanded_environment_name)
      Gitlab::Ci::Variables::Collection.new.tap do |variables|
269 270 271 272
        variables.concat(predefined_variables)
        variables.concat(project.predefined_variables)
        variables.concat(pipeline.predefined_variables)
        variables.concat(runner.predefined_variables) if runner
273
        variables.concat(project.deployment_variables(environment: environment)) if environment
274 275
        variables.concat(yaml_variables)
        variables.concat(user_variables)
276 277
        variables.concat(secret_group_variables)
        variables.concat(secret_project_variables(environment: environment))
278 279 280 281
        variables.concat(trigger_request.user_variables) if trigger_request
        variables.concat(pipeline.variables)
        variables.concat(pipeline.pipeline_schedule.job_variables) if pipeline.pipeline_schedule
      end
282
    end
283

284 285 286 287 288 289 290 291 292 293 294
    ##
    # Variables that do not depend on the environment name.
    #
    def simple_variables
      scoped_variables(environment: nil).to_runner_variables
    end

    ##
    # All variables, including persisted environment variables.
    #
    def variables
295 296 297
      Gitlab::Ci::Variables::Collection.new
        .concat(persisted_variables)
        .concat(scoped_variables)
298 299 300 301 302 303
        .concat(persisted_environment_variables)
        .to_runner_variables
    end

    def variables_hash
      scoped_variables.to_hash
304 305
    end

306 307 308 309
    def features
      { trace_sections: true }
    end

310
    def merge_request
Z
Z.J. van de Weg 已提交
311
      return @merge_request if defined?(@merge_request)
Z
Z.J. van de Weg 已提交
312

313 314
      @merge_request ||=
        begin
315
          merge_requests = MergeRequest.includes(:latest_merge_request_diff)
316 317
            .where(source_branch: ref,
                   source_project: pipeline.project)
Z
Z.J. van de Weg 已提交
318
            .reorder(iid: :desc)
319 320

          merge_requests.find do |merge_request|
321
            merge_request.commit_shas.include?(pipeline.sha)
322 323
          end
        end
324 325
    end

D
Douwe Maan 已提交
326
    def repo_url
K
Kamil Trzcinski 已提交
327
      auth = "gitlab-ci-token:#{ensure_token!}@"
328
      project.http_url_to_repo.sub(%r{^https?://}) do |prefix|
K
Kamil Trzcinski 已提交
329 330
        prefix + auth
      end
D
Douwe Maan 已提交
331 332 333
    end

    def allow_git_fetch
K
Kamil Trzcinski 已提交
334
      project.build_allow_git_fetch
D
Douwe Maan 已提交
335 336 337
    end

    def update_coverage
338
      coverage = trace.extract_coverage(coverage_regex)
339
      update_attributes(coverage: coverage) if coverage.present?
D
Douwe Maan 已提交
340 341
    end

342
    def parse_trace_sections!
343
      ExtractSectionsFromBuildTraceService.new(project, user).execute(self)
344 345
    end

346 347
    def trace
      Gitlab::Ci::Trace.new(self)
348 349
    end

350
    def has_trace?
351
      trace.exist?
T
Tomasz Maczukin 已提交
352 353
    end

354 355
    def trace=(data)
      raise NotImplementedError
T
Tomasz Maczukin 已提交
356 357
    end

358 359
    def old_trace
      read_attribute(:trace)
360 361
    end

362
    def erase_old_trace!
363
      update_column(:trace, nil)
D
Douwe Maan 已提交
364 365
    end

366 367 368 369
    def needs_touch?
      Time.now - updated_at > 15.minutes.to_i
    end

L
Lin Jen-Shin 已提交
370
    def valid_token?(token)
371
      self.token && ActiveSupport::SecurityUtils.variable_size_secure_compare(token, self.token)
K
Kamil Trzcinski 已提交
372 373
    end

374 375 376 377
    def has_tags?
      tag_list.any?
    end

378
    def any_runners_online?
379
      project.any_runners? { |runner| runner.active? && runner.online? && runner.can_pick?(self) }
380 381
    end

K
Kamil Trzcinski 已提交
382
    def stuck?
383 384 385
      pending? && !any_runners_online?
    end

386
    def execute_hooks
387
      return unless project
388

389
      build_data = Gitlab::DataBuilder::Build.build(self)
390 391
      project.execute_hooks(build_data.dup, :job_hooks)
      project.execute_services(build_data.dup, :job_hooks)
392
      PagesService.new(build_data).execute
J
Josh Frye 已提交
393
      project.running_or_pending_build_count(force: true)
394 395
    end

396 397 398 399
    def browsable_artifacts?
      artifacts_metadata?
    end

400
    def artifacts_metadata_entry(path, **options)
401 402 403 404 405
      artifacts_metadata.use_file do |metadata_path|
        metadata = Gitlab::Ci::Build::Artifacts::Metadata.new(
          metadata_path,
          path,
          **options)
406

407 408
        metadata.to_entry
      end
409 410
    end

411 412 413
    def erase_artifacts!
      remove_artifacts_file!
      remove_artifacts_metadata!
414
      save
415 416
    end

417 418 419
    def erase(opts = {})
      return false unless erasable?

420
      erase_artifacts!
421 422 423 424 425 426 427 428 429 430 431 432
      erase_trace!
      update_erased!(opts[:erased_by])
    end

    def erasable?
      complete? && (artifacts? || has_trace?)
    end

    def erased?
      !self.erased_at.nil?
    end

433
    def artifacts_expired?
434
      artifacts_expire_at && artifacts_expire_at < Time.now
435 436
    end

437 438 439 440 441
    def artifacts_expire_in
      artifacts_expire_at - Time.now if artifacts_expire_at
    end

    def artifacts_expire_in=(value)
K
Kamil Trzcinski 已提交
442 443
      self.artifacts_expire_at =
        if value
444
          ChronicDuration.parse(value)&.seconds&.from_now
K
Kamil Trzcinski 已提交
445
        end
446 447
    end

448
    def has_expiring_artifacts?
Z
Z.J. van de Weg 已提交
449
      artifacts_expire_at.present? && artifacts_expire_at > Time.now
450 451
    end

452
    def keep_artifacts!
453
      self.update(artifacts_expire_at: nil)
454
      self.job_artifacts.update_all(expire_at: nil)
455 456
    end

457
    def coverage_regex
458
      super || project.try(:build_coverage_regex)
459 460
    end

461 462
    def when
      read_attribute(:when) || build_attributes_from_config[:when] || 'on_success'
463 464
    end

465 466
    def yaml_variables
      read_attribute(:yaml_variables) || build_attributes_from_config[:yaml_variables] || []
467 468
    end

469
    def user_variables
470 471
      Gitlab::Ci::Variables::Collection.new.tap do |variables|
        return variables if user.blank?
472

473 474 475 476 477
        variables.append(key: 'GITLAB_USER_ID', value: user.id.to_s)
        variables.append(key: 'GITLAB_USER_EMAIL', value: user.email)
        variables.append(key: 'GITLAB_USER_LOGIN', value: user.username)
        variables.append(key: 'GITLAB_USER_NAME', value: user.name)
      end
478 479
    end

480 481 482 483 484 485 486
    def secret_group_variables
      return [] unless project.group

      project.group.secret_variables_for(ref, project)
    end

    def secret_project_variables(environment: persisted_environment)
L
Lin Jen-Shin 已提交
487 488 489
      project.secret_variables_for(ref: ref, environment: environment)
    end

490
    def steps
T
Tomasz Maczukin 已提交
491 492
      [Gitlab::Ci::Build::Step.from_commands(self),
       Gitlab::Ci::Build::Step.from_after_script(self)].compact
493 494 495
    end

    def image
496
      Gitlab::Ci::Build::Image.from_image(self)
497 498 499
    end

    def services
500
      Gitlab::Ci::Build::Image.from_services(self)
501 502
    end

503
    def artifacts
504
      [options[:artifacts]]
505 506 507
    end

    def cache
M
Matija Čupić 已提交
508 509 510 511
      cache = options[:cache]

      if cache && project.jobs_cache_index
        cache = cache.merge(
512
          key: "#{cache[:key]}-#{project.jobs_cache_index}")
513
      end
M
Matija Čupić 已提交
514 515

      [cache]
516 517
    end

518
    def credentials
519
      Gitlab::Ci::Build::Credentials::Factory.new(self).create!
520 521
    end

T
Tomasz Maczukin 已提交
522
    def dependencies
523 524
      return [] if empty_dependencies?

T
Tomasz Maczukin 已提交
525 526
      depended_jobs = depends_on_builds

527
      return depended_jobs unless options[:dependencies].present?
T
Tomasz Maczukin 已提交
528

529 530
      depended_jobs.select do |job|
        options[:dependencies].include?(job.name)
T
Tomasz Maczukin 已提交
531 532 533
      end
    end

534 535 536 537
    def empty_dependencies?
      options[:dependencies]&.empty?
    end

538
    def validates_dependencies!
539 540
      dependencies.each do |dependency|
        raise MissingDependenciesError unless dependency.valid_dependency?
541
      end
542 543
    end

S
Shinya Maeda 已提交
544 545 546 547 548 549 550
    def valid_dependency?
      return false if artifacts_expired?
      return false if erased?

      true
    end

551 552 553 554
    def hide_secrets(trace)
      return unless trace

      trace = trace.dup
555 556
      Gitlab::Ci::MaskSecret.mask!(trace, project.runners_token) if project
      Gitlab::Ci::MaskSecret.mask!(trace, token)
557 558 559
      trace
    end

560
    def serializable_hash(options = {})
J
James Lopez 已提交
561
      super(options).merge(when: read_attribute(:when))
562 563
    end

564 565
    private

L
Lin Jen-Shin 已提交
566
    def update_artifacts_size
K
Kamil Trzcinski 已提交
567
      self.artifacts_size = legacy_artifacts_file&.size
L
Lin Jen-Shin 已提交
568 569
    end

570
    def erase_trace!
571
      trace.erase!
572 573 574
    end

    def update_erased!(user = nil)
575
      self.update(erased_by: user, erased_at: Time.now, artifacts_expire_at: nil)
576 577
    end

578
    def unscoped_project
K
Kamil Trzciński 已提交
579
      @unscoped_project ||= Project.unscoped.find_by(id: project_id)
580 581
    end

582 583
    CI_REGISTRY_USER = 'gitlab-ci-token'.freeze

584 585 586 587 588 589 590 591 592 593 594 595 596 597 598
    def persisted_variables
      Gitlab::Ci::Variables::Collection.new.tap do |variables|
        return variables unless persisted?

        variables
          .append(key: 'CI_JOB_ID', value: id.to_s)
          .append(key: 'CI_JOB_TOKEN', value: token, public: false)
          .append(key: 'CI_BUILD_ID', value: id.to_s)
          .append(key: 'CI_BUILD_TOKEN', value: token, public: false)
          .append(key: 'CI_REGISTRY_USER', value: CI_REGISTRY_USER)
          .append(key: 'CI_REGISTRY_PASSWORD', value: token, public: false)
          .append(key: 'CI_REPOSITORY_URL', value: repo_url, public: false)
      end
    end

599
    def predefined_variables
600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616
      Gitlab::Ci::Variables::Collection.new.tap do |variables|
        variables.append(key: 'CI', value: 'true')
        variables.append(key: 'GITLAB_CI', value: 'true')
        variables.append(key: 'GITLAB_FEATURES', value: project.namespace.features.join(','))
        variables.append(key: 'CI_SERVER_NAME', value: 'GitLab')
        variables.append(key: 'CI_SERVER_VERSION', value: Gitlab::VERSION)
        variables.append(key: 'CI_SERVER_REVISION', value: Gitlab::REVISION)
        variables.append(key: 'CI_JOB_NAME', value: name)
        variables.append(key: 'CI_JOB_STAGE', value: stage)
        variables.append(key: 'CI_COMMIT_SHA', value: sha)
        variables.append(key: 'CI_COMMIT_REF_NAME', value: ref)
        variables.append(key: 'CI_COMMIT_REF_SLUG', value: ref_slug)
        variables.append(key: "CI_COMMIT_TAG", value: ref) if tag?
        variables.append(key: "CI_PIPELINE_TRIGGERED", value: 'true') if trigger_request
        variables.append(key: "CI_JOB_MANUAL", value: 'true') if action?
        variables.concat(legacy_variables)
      end
617 618 619
    end

    def legacy_variables
620 621 622 623 624 625 626 627 628 629 630
      Gitlab::Ci::Variables::Collection.new.tap do |variables|
        variables.append(key: 'CI_BUILD_REF', value: sha)
        variables.append(key: 'CI_BUILD_BEFORE_SHA', value: before_sha)
        variables.append(key: 'CI_BUILD_REF_NAME', value: ref)
        variables.append(key: 'CI_BUILD_REF_SLUG', value: ref_slug)
        variables.append(key: 'CI_BUILD_NAME', value: name)
        variables.append(key: 'CI_BUILD_STAGE', value: stage)
        variables.append(key: "CI_BUILD_TAG", value: ref) if tag?
        variables.append(key: "CI_BUILD_TRIGGERED", value: 'true') if trigger_request
        variables.append(key: "CI_BUILD_MANUAL", value: 'true') if action?
      end
631
    end
632

633 634 635 636 637 638 639 640 641 642 643 644 645
    def persisted_environment_variables
      Gitlab::Ci::Variables::Collection.new.tap do |variables|
        return variables unless persisted? && persisted_environment.present?

        variables.concat(persisted_environment.predefined_variables)

        # Here we're passing unexpanded environment_url for runner to expand,
        # and we need to make sure that CI_ENVIRONMENT_NAME and
        # CI_ENVIRONMENT_SLUG so on are available for the URL be expanded.
        variables.append(key: 'CI_ENVIRONMENT_URL', value: environment_url) if environment_url
      end
    end

646
    def environment_url
647
      options&.dig(:environment, :url) || persisted_environment&.external_url
648 649
    end

650 651
    def build_attributes_from_config
      return {} unless pipeline.config_processor
652

653 654
      pipeline.config_processor.build_attributes(name)
    end
655

656 657 658 659 660
    def update_project_statistics
      return unless project

      ProjectCacheWorker.perform_async(project_id, [], [:build_artifacts_size])
    end
661 662 663 664 665 666

    def update_project_statistics_after_save
      if previous_changes.include?('artifacts_size')
        update_project_statistics
      end
    end
D
Douwe Maan 已提交
667 668
  end
end