Commit 63b8dcea authored by Marc Shaw's avatar Marc Shaw

Ensure the pipeline's iid is set before skipping

Issue: gitlab.com/gitlab-org/gitlab/-/issues/325861
MR: gitlab.com/gitlab-org/gitlab/-/merge_requests/59342
parent cca73fcf
---
name: ci_pipeline_ensure_iid_on_skip
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/59342
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/327661
milestone: '13.12'
type: development
group: group::code review
default_enabled: false
...@@ -11,7 +11,16 @@ module Gitlab ...@@ -11,7 +11,16 @@ module Gitlab
def perform! def perform!
if skipped? if skipped?
@pipeline.skip if @command.save_incompleted if @command.save_incompleted
if Feature.enabled?(:ci_pipeline_ensure_iid_on_skip, @pipeline.project, default_enabled: :yaml)
# 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 skip call
# which it will lock the InternalId row for the whole transaction
@pipeline.ensure_project_iid!
end
@pipeline.skip
end
end end
end end
......
...@@ -21,17 +21,37 @@ RSpec.describe Gitlab::Ci::Pipeline::Chain::Skip do ...@@ -21,17 +21,37 @@ RSpec.describe Gitlab::Ci::Pipeline::Chain::Skip do
before do before do
allow(pipeline).to receive(:git_commit_message) allow(pipeline).to receive(:git_commit_message)
.and_return('commit message [ci skip]') .and_return('commit message [ci skip]')
step.perform!
end end
it 'breaks the chain' do it 'breaks the chain' do
step.perform!
expect(step.break?).to be true expect(step.break?).to be true
end end
it 'skips the pipeline' do it 'skips the pipeline' do
step.perform!
expect(pipeline.reload).to be_skipped expect(pipeline.reload).to be_skipped
end end
it 'calls ensure_project_iid explicitly' do
expect(pipeline).to receive(:ensure_project_iid!)
step.perform!
end
context 'when the ci_pipeline_ensure_iid_on_save feature flag is off' do
before do
stub_feature_flags(ci_pipeline_ensure_iid_on_skip: false)
end
it 'does not call ensure_project_iid explicitly' do
expect(pipeline).not_to receive(:ensure_project_iid!)
step.perform!
end
end
end end
context 'when pipeline has not been skipped' do context 'when pipeline has not been skipped' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment