Commit 7e4fcfb0 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Merge branch 'fix-mr-pipelines-run-on-regex' into 'master'

Fix MR pipelines run on only: regexp

Closes #55026

See merge request gitlab-org/gitlab-ce!23657
parents f03d5817 eb1956c5
...@@ -32,6 +32,9 @@ module Gitlab ...@@ -32,6 +32,9 @@ module Gitlab
return true if pipeline.source == pattern return true if pipeline.source == pattern
return true if pipeline.source&.pluralize == pattern return true if pipeline.source&.pluralize == pattern
# patterns can be matched only when branch or tag is used
# the pattern matching does not work for merge requests pipelines
if pipeline.branch? || pipeline.tag?
if pattern.first == "/" && pattern.last == "/" if pattern.first == "/" && pattern.last == "/"
Regexp.new(pattern[1...-1]) =~ pipeline.ref Regexp.new(pattern[1...-1]) =~ pipeline.ref
else else
...@@ -42,4 +45,5 @@ module Gitlab ...@@ -42,4 +45,5 @@ module Gitlab
end end
end end
end end
end
end end
...@@ -810,6 +810,64 @@ describe Ci::CreatePipelineService do ...@@ -810,6 +810,64 @@ describe Ci::CreatePipelineService do
end end
end end
end end
context "when config uses regular expression for only keyword" do
let(:config) do
{
build: {
stage: 'build',
script: 'echo',
only: ["/^#{ref_name}$/"]
}
}
end
context 'when merge request is specified' do
let(:merge_request) do
create(:merge_request,
source_project: project,
source_branch: ref_name,
target_project: project,
target_branch: 'master')
end
it 'does not create a merge request pipeline' do
expect(pipeline).not_to be_persisted
expect(pipeline.errors[:base])
.to eq(['No stages / jobs for this pipeline.'])
end
end
end
context "when config has 'except: [tags]'" do
let(:config) do
{
build: {
stage: 'build',
script: 'echo',
except: ['tags']
}
}
end
context 'when merge request is specified' do
let(:merge_request) do
create(:merge_request,
source_project: project,
source_branch: ref_name,
target_project: project,
target_branch: 'master')
end
it 'does not create a merge request pipeline' do
expect(pipeline).not_to be_persisted
expect(pipeline.errors[:base])
.to eq(['No stages / jobs for this pipeline.'])
end
end
end
end end
context 'when source is web' do context 'when source is web' 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