Class: Ci::Build

Constant Summary collapse

BuildArchivedError =
Class.new(StandardError)
RUNNER_FEATURES =
{
  upload_multiple_artifacts: -> (build) { build.publishes_artifacts_reports? },
  refspecs: -> (build) { build.merge_request_ref? },
  artifacts_exclude: -> (build) { build.supports_artifacts_exclude? },
  multi_build_steps: -> (build) { build.multi_build_steps? }
}.freeze
DEFAULT_RETRIES =
{
  scheduler_failure: 2
}.freeze
DEGRADATION_THRESHOLD_VARIABLE_NAME =
'DEGRADATION_THRESHOLD'

Constants included from HasStatus

HasStatus::ACTIVE_STATUSES, HasStatus::AVAILABLE_STATUSES, HasStatus::BLOCKED_STATUS, HasStatus::COMPLETED_STATUSES, HasStatus::DEFAULT_STATUS, HasStatus::EXCLUDE_IGNORED_STATUSES, HasStatus::ORDERED_STATUSES, HasStatus::PASSED_WITH_WARNINGS_STATUSES, HasStatus::STARTED_STATUSES, HasStatus::STATUSES_ENUM, HasStatus::UnknownStatusError

Instance Attribute Summary

Attributes included from Importable

#imported, #importing

Class Method Summary collapse

Instance Method Summary collapse

Methods included from HasRef

#branch?, #git_ref, #ref_slug

Methods included from Presentable

#present

Methods included from ObjectStorage::BackgroundMove

#background_upload, #changed_mounts

Methods included from AfterCommitQueue

#run_after_commit, #run_after_commit_or_now

Methods included from Contextable

#deployment_variables, #predefined_variables, #scoped_variables, #scoped_variables_hash, #secret_group_variables, #secret_instance_variables, #secret_project_variables, #simple_variables, #simple_variables_without_dependencies, #user_variables

Methods included from Metadatable

#degenerate!, #degenerated?, #ensure_metadata, #interruptible, #interruptible=, #options, #options=, #yaml_variables, #yaml_variables=

Methods inherited from Processable

#aggregated_needs_names, #ensure_scheduling_type!, #find_legacy_scheduling_type, #needs_attributes, populate_scheduling_type!, #scheduling_type_dag?, #scoped_variables_hash, select_with_aggregated_needs, #when

Methods included from Gitlab::Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

Methods inherited from CommitStatus

#all_met_to_become_pending?, #auto_canceled?, #duration, #failed_but_allowed?, #group_name, #importing?, #latest?, #locking_enabled?, locking_enabled?, names, #recoverable?, #sortable_name, update_as_processed!

Methods included from BulkInsertableAssociations

#bulk_insert_associations!, bulk_inserts_enabled?, with_bulk_insert

Methods included from HasStatus

#active?, #blocked?, #complete?, #started?

Methods inherited from ApplicationRecord

at_most, id_in, id_not_in, iid_in, pluck_primary_key, primary_key_in, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, underscore, without_order

Class Method Details

.first_pendingObject


204
205
206
# File 'app/models/ci/build.rb', line 204

def first_pending
  pending.unstarted.order('created_at ASC').first
end

.keep_artifacts!Object


784
785
786
787
# File 'app/models/ci/build.rb', line 784

def self.keep_artifacts!
  update_all(artifacts_expire_at: nil)
  Ci::JobArtifact.where(job: self.select(:id)).update_all(expire_at: nil)
end

.model_nameObject

This is needed for url_for to work, as the controller is JobsController


200
201
202
# File 'app/models/ci/build.rb', line 200

def model_name
  ActiveModel::Name.new(self, nil, 'job')
end

.retry(build, current_user) ⇒ Object


208
209
210
211
212
213
214
# File 'app/models/ci/build.rb', line 208

def retry(build, current_user)
  # rubocop: disable CodeReuse/ServiceClass
  Ci::RetryBuildService
    .new(build.project, current_user)
    .execute(build)
  # rubocop: enable CodeReuse/ServiceClass
end

.with_preloadsObject


216
217
218
# File 'app/models/ci/build.rb', line 216

def with_preloads
  preload(:job_artifacts_archive, :job_artifacts, project: [:namespace])
end

Instance Method Details

#action?Boolean

Returns:

  • (Boolean)

424
425
426
# File 'app/models/ci/build.rb', line 424

def action?
  %w[manual delayed].include?(self.when)
end

#all_dependenciesObject


831
832
833
# File 'app/models/ci/build.rb', line 831

def all_dependencies
  dependencies.all
end

#allow_git_fetchObject


606
607
608
# File 'app/models/ci/build.rb', line 606

def allow_git_fetch
  project.build_allow_git_fetch
end

#any_runners_online?Boolean

Returns:

  • (Boolean)

714
715
716
# File 'app/models/ci/build.rb', line 714

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

#any_unmet_prerequisites?Boolean

Returns:

  • (Boolean)

448
449
450
# File 'app/models/ci/build.rb', line 448

def any_unmet_prerequisites?
  prerequisites.present?
end

#archived?Boolean

Returns:

  • (Boolean)

405
406
407
408
409
410
# File 'app/models/ci/build.rb', line 405

def archived?
  return true if degenerated?

  archive_builds_older_than = Gitlab::CurrentSettings.current_application_settings.archive_builds_older_than
  archive_builds_older_than.present? && created_at < archive_builds_older_than
end

#artifacts?Boolean

Returns:

  • (Boolean)

649
650
651
# File 'app/models/ci/build.rb', line 649

def artifacts?
  !artifacts_expired? && artifacts_file&.exists?
end

#artifacts_expire_inObject


769
770
771
# File 'app/models/ci/build.rb', line 769

def artifacts_expire_in
  artifacts_expire_at - Time.current if artifacts_expire_at
end

#artifacts_expire_in=(value) ⇒ Object


773
774
775
776
777
778
# File 'app/models/ci/build.rb', line 773

def artifacts_expire_in=(value)
  self.artifacts_expire_at =
    if value
      ChronicDuration.parse(value)&.seconds&.from_now
    end
end

#artifacts_expired?Boolean

Returns:

  • (Boolean)

765
766
767
# File 'app/models/ci/build.rb', line 765

def artifacts_expired?
  artifacts_expire_at && artifacts_expire_at < Time.current
end

#artifacts_expose_asObject


694
695
696
# File 'app/models/ci/build.rb', line 694

def artifacts_expose_as
  options.dig(:artifacts, :expose_as)
end

#artifacts_fileObject


637
638
639
# File 'app/models/ci/build.rb', line 637

def artifacts_file
  job_artifacts_archive&.file
end

#artifacts_file_for_type(type) ⇒ Object


794
795
796
# File 'app/models/ci/build.rb', line 794

def artifacts_file_for_type(type)
  job_artifacts.find_by(file_type: Ci::JobArtifact.file_types[type])&.file
end

#artifacts_metadataObject


645
646
647
# File 'app/models/ci/build.rb', line 645

def 
  &.file
end

#artifacts_metadata?Boolean

Returns:

  • (Boolean)

664
665
666
# File 'app/models/ci/build.rb', line 664

def artifacts_metadata?
  artifacts? && &.exists?
end

#artifacts_metadata_entry(path, **options) ⇒ Object


733
734
735
736
737
738
739
740
741
742
# File 'app/models/ci/build.rb', line 733

def (path, **options)
  .open do ||
     = Gitlab::Ci::Build::Artifacts::Metadata.new(
      ,
      path,
      **options)

    .to_entry
  end
end

#artifacts_pathsObject


698
699
700
# File 'app/models/ci/build.rb', line 698

def artifacts_paths
  options.dig(:artifacts, :paths)
end

#artifacts_sizeObject


641
642
643
# File 'app/models/ci/build.rb', line 641

def artifacts_size
  job_artifacts_archive&.size
end

#auto_retry_allowed?Boolean

Returns:

  • (Boolean)

378
379
380
# File 'app/models/ci/build.rb', line 378

def auto_retry_allowed?
  auto_retry.allowed?
end

#available_artifacts?Boolean

This method is similar to #artifacts? but it includes the artifacts locking mechanics. A new method was created to prevent breaking existing behavior and avoid introducing N+1s.

Returns:

  • (Boolean)

660
661
662
# File 'app/models/ci/build.rb', line 660

def available_artifacts?
  (!artifacts_expired? || pipeline.artifacts_locked?) && job_artifacts_archive&.exists?
end

#browsable_artifacts?Boolean

Returns:

  • (Boolean)

729
730
731
# File 'app/models/ci/build.rb', line 729

def browsable_artifacts?
  artifacts_metadata?
end

#cacheObject


816
817
818
819
820
821
822
823
824
825
# File 'app/models/ci/build.rb', line 816

def cache
  cache = options[:cache]

  if cache && project.jobs_cache_index
    cache = cache.merge(
      key: "#{cache[:key]}-#{project.jobs_cache_index}")
  end

  [cache]
end

#cancelable?Boolean

rubocop: enable CodeReuse/ServiceClass

Returns:

  • (Boolean)

436
437
438
# File 'app/models/ci/build.rb', line 436

def cancelable?
  active? || created?
end

#collect_accessibility_reports!(accessibility_report) ⇒ Object


906
907
908
909
910
911
912
# File 'app/models/ci/build.rb', line 906

def collect_accessibility_reports!(accessibility_report)
  each_report(Ci::JobArtifact::ACCESSIBILITY_REPORT_FILE_TYPES) do |file_type, blob|
    Gitlab::Ci::Parsers.fabricate!(file_type).parse!(blob, accessibility_report)
  end

  accessibility_report
end

#collect_coverage_reports!(coverage_report) ⇒ Object


914
915
916
917
918
919
920
# File 'app/models/ci/build.rb', line 914

def collect_coverage_reports!(coverage_report)
  each_report(Ci::JobArtifact::COVERAGE_REPORT_FILE_TYPES) do |file_type, blob|
    Gitlab::Ci::Parsers.fabricate!(file_type).parse!(blob, coverage_report)
  end

  coverage_report
end

#collect_terraform_reports!(terraform_reports) ⇒ Object


922
923
924
925
926
927
928
# File 'app/models/ci/build.rb', line 922

def collect_terraform_reports!(terraform_reports)
  each_report(::Ci::JobArtifact::TERRAFORM_REPORT_FILE_TYPES) do |file_type, blob, report_artifact|
    ::Gitlab::Ci::Parsers.fabricate!(file_type).parse!(blob, terraform_reports, artifact: report_artifact)
  end

  terraform_reports
end

#collect_test_reports!(test_reports) ⇒ Object


898
899
900
901
902
903
904
# File 'app/models/ci/build.rb', line 898

def collect_test_reports!(test_reports)
  test_reports.get_suite(group_name).tap do |test_suite|
    each_report(Ci::JobArtifact::TEST_REPORT_FILE_TYPES) do |file_type, blob|
      Gitlab::Ci::Parsers.fabricate!(file_type).parse!(blob, test_suite, job: self)
    end
  end
end

#coverage_regexObject


798
799
800
# File 'app/models/ci/build.rb', line 798

def coverage_regex
  super || project.try(:build_coverage_regex)
end

#credentialsObject


827
828
829
# File 'app/models/ci/build.rb', line 827

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

#degradation_thresholdObject


954
955
956
957
# File 'app/models/ci/build.rb', line 954

def degradation_threshold
  var = yaml_variables.find { |v| v[:key] == DEGRADATION_THRESHOLD_VARIABLE_NAME }
  var[:value]&.to_i if var
end

#dependency_variablesObject


579
580
581
582
583
584
585
# File 'app/models/ci/build.rb', line 579

def dependency_variables
  return [] if all_dependencies.empty?

  Gitlab::Ci::Variables::Collection.new.concat(
    Ci::JobVariable.where(job: all_dependencies).dotenv_source
  )
end

#deploy_token_variablesObject


570
571
572
573
574
575
576
577
# File 'app/models/ci/build.rb', line 570

def deploy_token_variables
  Gitlab::Ci::Variables::Collection.new.tap do |variables|
    break variables unless gitlab_deploy_token

    variables.append(key: 'CI_DEPLOY_USER', value: gitlab_deploy_token.username)
    variables.append(key: 'CI_DEPLOY_PASSWORD', value: gitlab_deploy_token.token, public: false, masked: true)
  end
end

#deployment_statusObject

Virtual deployment status depending on the environment status.


935
936
937
938
939
940
941
942
943
944
945
# File 'app/models/ci/build.rb', line 935

def deployment_status
  return unless starts_environment?

  if success?
    return successful_deployment_status
  elsif failed?
    return :failed
  end

  :creating
end

#detailed_status(current_user) ⇒ Object


382
383
384
385
386
# File 'app/models/ci/build.rb', line 382

def detailed_status(current_user)
  Gitlab::Ci::Status::Build::Factory
    .new(self, current_user)
    .fabricate!
end

#doom!Object

Consider this object to have a structural integrity problems


948
949
950
951
952
# File 'app/models/ci/build.rb', line 948

def doom!
  update_columns(
    status: :failed,
    failure_reason: :data_integrity_failure)
end

#environment_actionObject


498
499
500
# File 'app/models/ci/build.rb', line 498

def environment_action
  self.options.fetch(:environment, {}).fetch(:action, 'start') if self.options
end

#environment_changed_page_variablesObject


561
562
563
564
565
566
567
568
# File 'app/models/ci/build.rb', line 561

def environment_changed_page_variables
  Gitlab::Ci::Variables::Collection.new.tap do |variables|
    break variables unless environment_status && Feature.enabled?(:modifed_path_ci_variables, project)

    variables.append(key: 'CI_MERGE_REQUEST_CHANGED_PAGE_PATHS', value: environment_status.changed_paths.join(','))
    variables.append(key: 'CI_MERGE_REQUEST_CHANGED_PAGE_URLS', value: environment_status.changed_urls.join(','))
  end
end

#erasable?Boolean

Returns:

  • (Boolean)

757
758
759
# File 'app/models/ci/build.rb', line 757

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

#erase(opts = {}) ⇒ Object


749
750
751
752
753
754
755
# File 'app/models/ci/build.rb', line 749

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

  job_artifacts.destroy_all # rubocop: disable Cop/DestroyAll
  erase_trace!
  update_erased!(opts[:erased_by])
end

#erase_erasable_artifacts!Object

and use that for `ExpireBuildInstanceArtifactsWorker`?


745
746
747
# File 'app/models/ci/build.rb', line 745

def erase_erasable_artifacts!
  job_artifacts.erasable.destroy_all # rubocop: disable Cop/DestroyAll
end

#erase_old_trace!Object


688
689
690
691
692
# File 'app/models/ci/build.rb', line 688

def erase_old_trace!
  return unless has_old_trace?

  update_column(:trace, nil)
end

#erased?Boolean

Returns:

  • (Boolean)

761
762
763
# File 'app/models/ci/build.rb', line 761

def erased?
  !self.erased_at.nil?
end

#execute_hooksObject


722
723
724
725
726
727
# File 'app/models/ci/build.rb', line 722

def execute_hooks
  return unless project

  project.execute_hooks(build_data.dup, :job_hooks) if project.has_active_hooks?(:job_hooks)
  project.execute_services(build_data.dup, :job_hooks) if project.has_active_services?(:job_hooks)
end

#expanded_environment_nameObject


456
457
458
459
460
461
462
463
464
465
466
467
468
# File 'app/models/ci/build.rb', line 456

def expanded_environment_name
  return unless has_environment?

  strong_memoize(:expanded_environment_name) do
    # We're using a persisted expanded environment name in order to avoid
    # variable expansion per request.
    if &.expanded_environment_name.present?
      .expanded_environment_name
    else
      ExpandVariables.expand(environment, -> { simple_variables })
    end
  end
end

#expanded_kubernetes_namespaceObject


470
471
472
473
474
475
476
477
478
479
480
# File 'app/models/ci/build.rb', line 470

def expanded_kubernetes_namespace
  return unless has_environment?

  namespace = options.dig(:environment, :kubernetes, :namespace)

  if namespace.present?
    strong_memoize(:expanded_kubernetes_namespace) do
      ExpandVariables.expand(namespace, -> { simple_variables })
    end
  end
end

#featuresObject


587
588
589
# File 'app/models/ci/build.rb', line 587

def features
  { trace_sections: true }
end

#has_archived_trace?Boolean

Returns:

  • (Boolean)

633
634
635
# File 'app/models/ci/build.rb', line 633

def has_archived_trace?
  trace.archived_trace_exist?
end

#has_environment?Boolean

Returns:

  • (Boolean)

486
487
488
# File 'app/models/ci/build.rb', line 486

def has_environment?
  environment.present?
end

#has_expiring_archive_artifacts?Boolean

Returns:

  • (Boolean)

780
781
782
# File 'app/models/ci/build.rb', line 780

def has_expiring_archive_artifacts?
  has_expiring_artifacts? && job_artifacts_archive.present?
end

#has_job_artifacts?Boolean

Returns:

  • (Boolean)

668
669
670
# File 'app/models/ci/build.rb', line 668

def has_job_artifacts?
  job_artifacts.any?
end

#has_live_trace?Boolean

Returns:

  • (Boolean)

629
630
631
# File 'app/models/ci/build.rb', line 629

def has_live_trace?
  trace.live_trace_exist?
end

#has_old_trace?Boolean

Returns:

  • (Boolean)

676
677
678
# File 'app/models/ci/build.rb', line 676

def has_old_trace?
  old_trace.present?
end

#has_tags?Boolean

Returns:

  • (Boolean)

710
711
712
# File 'app/models/ci/build.rb', line 710

def has_tags?
  tag_list.any?
end

#has_terminal?Boolean

Returns:

  • (Boolean)

894
895
896
# File 'app/models/ci/build.rb', line 894

def has_terminal?
  running? && runner_session_url.present?
end

#has_test_reports?Boolean

Returns:

  • (Boolean)

672
673
674
# File 'app/models/ci/build.rb', line 672

def has_test_reports?
  job_artifacts.test_reports.exists?
end

#has_trace?Boolean

Returns:

  • (Boolean)

625
626
627
# File 'app/models/ci/build.rb', line 625

def has_trace?
  trace.exist?
end

#has_valid_build_dependencies?Boolean

Returns:

  • (Boolean)

835
836
837
# File 'app/models/ci/build.rb', line 835

def has_valid_build_dependencies?
  dependencies.valid?
end

#hide_secrets(data, metrics = ::Gitlab::Ci::Trace::Metrics.new) ⇒ Object


877
878
879
880
881
882
883
884
885
886
887
888
# File 'app/models/ci/build.rb', line 877

def hide_secrets(data, metrics = ::Gitlab::Ci::Trace::Metrics.new)
  return unless trace

  data.dup.tap do |trace|
    Gitlab::Ci::MaskSecret.mask!(trace, project.runners_token) if project
    Gitlab::Ci::MaskSecret.mask!(trace, token) if token

    if trace != data
      metrics.increment_trace_operation(operation: :mutated)
    end
  end
end

#imageObject


808
809
810
# File 'app/models/ci/build.rb', line 808

def image
  Gitlab::Ci::Build::Image.from_image(self)
end

#invalid_dependenciesObject


839
840
841
# File 'app/models/ci/build.rb', line 839

def invalid_dependencies
  dependencies.invalid_local
end

#keep_artifacts!Object


789
790
791
792
# File 'app/models/ci/build.rb', line 789

def keep_artifacts!
  self.update(artifacts_expire_at: nil)
  self.job_artifacts.update_all(expire_at: nil)
end

#locked_artifacts?Boolean

Returns:

  • (Boolean)

653
654
655
# File 'app/models/ci/build.rb', line 653

def locked_artifacts?
  pipeline.artifacts_locked? && artifacts_file&.exists?
end

#merge_requestObject


591
592
593
594
595
# File 'app/models/ci/build.rb', line 591

def merge_request
  strong_memoize(:merge_request) do
    pipeline.all_merge_requests.order(iid: :asc).first
  end
end

#multi_build_steps?Boolean

Returns:

  • (Boolean)

873
874
875
# File 'app/models/ci/build.rb', line 873

def multi_build_steps?
  options.dig(:release)&.any?
end

#needs_touch?Boolean

Returns:

  • (Boolean)

702
703
704
# File 'app/models/ci/build.rb', line 702

def needs_touch?
  Time.current - updated_at > 15.minutes.to_i
end

#old_traceObject


684
685
686
# File 'app/models/ci/build.rb', line 684

def old_trace
  read_attribute(:trace)
end

#on_stopObject


510
511
512
# File 'app/models/ci/build.rb', line 510

def on_stop
  options&.dig(:environment, :on_stop)
end

#options_scheduled_atObject


420
421
422
# File 'app/models/ci/build.rb', line 420

def options_scheduled_at
  ChronicDuration.parse(options[:start_in])&.seconds&.from_now
end

#other_manual_actionsObject


388
389
390
# File 'app/models/ci/build.rb', line 388

def other_manual_actions
  pipeline.manual_actions.where.not(name: name)
end

#other_scheduled_actionsObject


392
393
394
# File 'app/models/ci/build.rb', line 392

def other_scheduled_actions
  pipeline.scheduled_actions.where.not(name: name)
end

#outdated_deployment?Boolean

Returns:

  • (Boolean)

502
503
504
# File 'app/models/ci/build.rb', line 502

def outdated_deployment?
  success? && !deployment.try(:last?)
end

#pages_generator?Boolean

Returns:

  • (Boolean)

396
397
398
399
# File 'app/models/ci/build.rb', line 396

def pages_generator?
  Gitlab.config.pages.enabled &&
    self.name == 'pages'
end

#parse_trace_sections!Object

rubocop: disable CodeReuse/ServiceClass


616
617
618
# File 'app/models/ci/build.rb', line 616

def parse_trace_sections!
  ExtractSectionsFromBuildTraceService.new(project, user).execute(self)
end

#persisted_environmentObject

Since Gitlab 11.5, deployments records started being created right after `ci_builds` creation. We can look up a relevant `environment` through `deployment` relation today. (See more gitlab.com/gitlab-org/gitlab-foss/merge_requests/22380)

Since Gitlab 12.9, we started persisting the expanded environment name to avoid repeated variables expansion in `action: stop` builds as well.


72
73
74
75
76
77
78
# File 'app/models/ci/build.rb', line 72

def persisted_environment
  return unless has_environment?

  strong_memoize(:persisted_environment) do
    Environment.find_by(name: expanded_environment_name, project: project)
  end
end

#persisted_environment_variablesObject


548
549
550
551
552
553
554
555
556
557
558
559
# File 'app/models/ci/build.rb', line 548

def persisted_environment_variables
  Gitlab::Ci::Variables::Collection.new.tap do |variables|
    break 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

#persisted_variablesObject


530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
# File 'app/models/ci/build.rb', line 530

def persisted_variables
  Gitlab::Ci::Variables::Collection.new.tap do |variables|
    break variables unless persisted?

    variables
      .concat(pipeline.persisted_variables)
      .append(key: 'CI_JOB_ID', value: id.to_s)
      .append(key: 'CI_JOB_URL', value: Gitlab::Routing.url_helpers.project_job_url(project, self))
      .append(key: 'CI_JOB_TOKEN', value: token.to_s, public: false, masked: true)
      .append(key: 'CI_BUILD_ID', value: id.to_s)
      .append(key: 'CI_BUILD_TOKEN', value: token.to_s, public: false, masked: true)
      .append(key: 'CI_REGISTRY_USER', value: ::Gitlab::Auth::CI_JOB_USER)
      .append(key: 'CI_REGISTRY_PASSWORD', value: token.to_s, public: false, masked: true)
      .append(key: 'CI_REPOSITORY_URL', value: repo_url.to_s, public: false)
      .concat(deploy_token_variables)
  end
end

#play(current_user, job_variables_attributes = nil) ⇒ Object

rubocop: disable CodeReuse/ServiceClass


429
430
431
432
433
# File 'app/models/ci/build.rb', line 429

def play(current_user, job_variables_attributes = nil)
  Ci::PlayBuildService
    .new(project, current_user)
    .execute(self, job_variables_attributes)
end

#playable?Boolean

Returns:

  • (Boolean)

412
413
414
# File 'app/models/ci/build.rb', line 412

def playable?
  action? && !archived? && (manual? || scheduled? || retryable?)
end

#prerequisitesObject


452
453
454
# File 'app/models/ci/build.rb', line 452

def prerequisites
  Gitlab::Ci::Build::Prerequisite::Factory.new(self).unmet
end

#publishes_artifacts_reports?Boolean

Returns:

  • (Boolean)

864
865
866
# File 'app/models/ci/build.rb', line 864

def publishes_artifacts_reports?
  options&.dig(:artifacts, :reports)&.any?
end

#repo_urlObject


597
598
599
600
601
602
603
604
# File 'app/models/ci/build.rb', line 597

def repo_url
  return unless token

  auth = "#{::Gitlab::Auth::CI_JOB_USER}:#{token}@"
  project.http_url_to_repo.sub(%r{^https?://}) do |prefix|
    prefix + auth
  end
end

#report_artifactsObject


930
931
932
# File 'app/models/ci/build.rb', line 930

def report_artifacts
  job_artifacts.with_reports
end

#requires_resource?Boolean

Returns:

  • (Boolean)

482
483
484
# File 'app/models/ci/build.rb', line 482

def requires_resource?
  self.resource_group_id.present?
end

#retries_countObject


444
445
446
# File 'app/models/ci/build.rb', line 444

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

#retryable?Boolean

Returns:

  • (Boolean)

440
441
442
# File 'app/models/ci/build.rb', line 440

def retryable?
  !archived? && (success? || failed? || canceled?)
end

#runnable?Boolean

Returns:

  • (Boolean)

401
402
403
# File 'app/models/ci/build.rb', line 401

def runnable?
  true
end

#runner_required_feature_namesObject


850
851
852
853
854
855
856
# File 'app/models/ci/build.rb', line 850

def runner_required_feature_names
  strong_memoize(:runner_required_feature_names) do
    RUNNER_FEATURES.select do |feature, method|
      method.call(self)
    end.keys
  end
end

#schedulable?Boolean

Returns:

  • (Boolean)

416
417
418
# File 'app/models/ci/build.rb', line 416

def schedulable?
  self.when == 'delayed' && options[:start_in].present?
end

#serializable_hash(options = {}) ⇒ Object


890
891
892
# File 'app/models/ci/build.rb', line 890

def serializable_hash(options = {})
  super(options).merge(when: read_attribute(:when))
end

#servicesObject


812
813
814
# File 'app/models/ci/build.rb', line 812

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

#starts_environment?Boolean

Returns:

  • (Boolean)

490
491
492
# File 'app/models/ci/build.rb', line 490

def starts_environment?
  has_environment? && self.environment_action == 'start'
end

#stepsObject


802
803
804
805
806
# File 'app/models/ci/build.rb', line 802

def steps
  [Gitlab::Ci::Build::Step.from_commands(self),
   Gitlab::Ci::Build::Step.from_release(self),
   Gitlab::Ci::Build::Step.from_after_script(self)].compact
end

#stops_environment?Boolean

Returns:

  • (Boolean)

494
495
496
# File 'app/models/ci/build.rb', line 494

def stops_environment?
  has_environment? && self.environment_action == 'stop'
end

#stuck?Boolean

Returns:

  • (Boolean)

718
719
720
# File 'app/models/ci/build.rb', line 718

def stuck?
  pending? && !any_runners_online?
end

#supported_runner?(features) ⇒ Boolean

Returns:

  • (Boolean)

858
859
860
861
862
# File 'app/models/ci/build.rb', line 858

def supported_runner?(features)
  runner_required_feature_names.all? do |feature_name|
    features&.dig(feature_name)
  end
end

#supports_artifacts_exclude?Boolean

Returns:

  • (Boolean)

868
869
870
871
# File 'app/models/ci/build.rb', line 868

def supports_artifacts_exclude?
  options&.dig(:artifacts, :exclude)&.any? &&
    Gitlab::Ci::Features.artifacts_exclude_enabled?
end

#traceObject

rubocop: enable CodeReuse/ServiceClass


621
622
623
# File 'app/models/ci/build.rb', line 621

def trace
  Gitlab::Ci::Trace.new(self)
end

#trace=(data) ⇒ Object

Raises:

  • (NotImplementedError)

680
681
682
# File 'app/models/ci/build.rb', line 680

def trace=(data)
  raise NotImplementedError
end

#triggered_by?(current_user) ⇒ Boolean

Returns:

  • (Boolean)

506
507
508
# File 'app/models/ci/build.rb', line 506

def triggered_by?(current_user)
  user == current_user
end

#update_coverageObject


610
611
612
613
# File 'app/models/ci/build.rb', line 610

def update_coverage
  coverage = trace.extract_coverage(coverage_regex)
  update(coverage: coverage) if coverage.present?
end

#valid_dependency?Boolean

Returns:

  • (Boolean)

843
844
845
846
847
848
# File 'app/models/ci/build.rb', line 843

def valid_dependency?
  return false if artifacts_expired?
  return false if erased?

  true
end

#valid_token?(token) ⇒ Boolean

Returns:

  • (Boolean)

706
707
708
# File 'app/models/ci/build.rb', line 706

def valid_token?(token)
  self.token && ActiveSupport::SecurityUtils.secure_compare(token, self.token)
end

#variablesObject

All variables, including persisted environment variables.


517
518
519
520
521
522
523
524
525
526
527
528
# File 'app/models/ci/build.rb', line 517

def variables
  strong_memoize(:variables) do
    Gitlab::Ci::Variables::Collection.new
      .concat(persisted_variables)
      .concat(job_jwt_variables)
      .concat(scoped_variables)
      .concat(job_variables)
      .concat(environment_changed_page_variables)
      .concat(persisted_environment_variables)
      .to_runner_variables
  end
end