debian-mirror-gitlab/lib/gitlab/ci/pipeline/chain/helpers.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

54 lines
1.7 KiB
Ruby
Raw Normal View History

2018-12-13 13:39:08 +05:30
# frozen_string_literal: true
2018-03-17 18:26:18 +05:30
module Gitlab
module Ci
module Pipeline
module Chain
module Helpers
2020-01-01 13:55:28 +05:30
def error(message, config_error: false, drop_reason: nil)
2022-05-03 16:02:30 +05:30
sanitized_message = ActionController::Base.helpers.sanitize(message, tags: [])
2020-10-24 23:57:45 +05:30
if config_error
2020-01-01 13:55:28 +05:30
drop_reason = :config_error
2022-05-03 16:02:30 +05:30
pipeline.yaml_errors = sanitized_message
2019-12-04 20:38:33 +05:30
end
2022-05-03 16:02:30 +05:30
pipeline.add_error_message(sanitized_message)
2021-04-29 21:17:54 +05:30
drop_pipeline!(drop_reason)
2020-07-28 23:09:34 +05:30
# TODO: consider not to rely on AR errors directly as they can be
# polluted with other unrelated errors (e.g. state machine)
# https://gitlab.com/gitlab-org/gitlab/-/issues/220823
2022-05-03 16:02:30 +05:30
pipeline.errors.add(:base, sanitized_message)
2021-06-08 01:23:25 +05:30
pipeline.errors.full_messages
2018-03-17 18:26:18 +05:30
end
2020-07-28 23:09:34 +05:30
def warning(message)
2022-05-03 16:02:30 +05:30
sanitized_message = ActionController::Base.helpers.sanitize(message, tags: [])
pipeline.add_warning_message(sanitized_message)
2020-07-28 23:09:34 +05:30
end
2020-10-24 23:57:45 +05:30
2021-04-29 21:17:54 +05:30
private
def drop_pipeline!(drop_reason)
return if pipeline.readonly?
if drop_reason && command.save_incompleted
# Project iid must be called outside a transaction, so we ensure it is set here
# otherwise it may be set within the state transition transaction of the drop! call
# which it will lock the InternalId row for the whole transaction
pipeline.ensure_project_iid!
pipeline.drop!(drop_reason)
else
command.increment_pipeline_failure_reason_counter(drop_reason)
end
2020-10-24 23:57:45 +05:30
end
2018-03-17 18:26:18 +05:30
end
end
end
end
end