Skip to content
Snippets Groups Projects
Commit b30e0e06 authored by Grzegorz Bizon's avatar Grzegorz Bizon
Browse files

Fix invalid pipeline build chain tag evaluation

parent fe62860e
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -3,8 +3,6 @@ module Gitlab
module Pipeline
module Chain
class Build < Chain::Base
include Chain::Helpers
def perform!
@pipeline.assign_attributes(
source: @command.source,
Loading
Loading
@@ -51,6 +49,10 @@ module Gitlab
def protected_ref?
@project.protected_for?(ref)
end
def tag_exists?
project.repository.tag_exists?(ref)
end
end
end
end
Loading
Loading
Loading
Loading
@@ -3,16 +3,22 @@ module Gitlab
module Pipeline
module Chain
module Helpers
include Gitlab::Utils::StrongMemoize
def branch_exists?
return @is_branch if defined?(@is_branch)
strong_memoize(:is_branch) do
raise ArgumentError unless pipeline.ref
 
@is_branch = project.repository.branch_exists?(pipeline.ref)
project.repository.branch_exists?(pipeline.ref)
end
end
 
def tag_exists?
return @is_tag if defined?(@is_tag)
strong_memoize(:is_tag) do
raise ArgumentError unless pipeline.ref
 
@is_tag = project.repository.tag_exists?(pipeline.ref)
project.repository.tag_exists?(pipeline.ref)
end
end
 
def error(message)
Loading
Loading
Loading
Loading
@@ -21,31 +21,64 @@ describe Gitlab::Ci::Pipeline::Chain::Build do
 
before do
stub_repository_ci_yaml_file(sha: anything)
step.perform!
end
 
it 'never breaks the chain' do
step.perform!
expect(step.break?).to be false
end
 
it 'fills pipeline object with data' do
step.perform!
expect(pipeline.sha).not_to be_empty
expect(pipeline.sha).to eq project.commit.id
expect(pipeline.ref).to eq 'master'
expect(pipeline.tag).to be false
expect(pipeline.user).to eq user
expect(pipeline.project).to eq project
end
 
it 'sets a valid config source' do
step.perform!
expect(pipeline.repository_source?).to be true
end
 
it 'returns a valid pipeline' do
step.perform!
expect(pipeline).to be_valid
end
 
it 'does not persist a pipeline' do
step.perform!
expect(pipeline).not_to be_persisted
end
context 'when pipeline is running for a tag' do
let(:command) do
double('command', source: :push,
origin_ref: 'mytag',
checkout_sha: project.commit.id,
after_sha: nil,
before_sha: nil,
trigger_request: nil,
schedule: nil,
project: project,
current_user: user)
end
before do
allow(step).to receive(:tag_exists?).and_return(true)
step.perform!
end
it 'correctly indicated that this is a tagged pipeline' do
expect(pipeline).to be_tag
end
end
end
Loading
Loading
@@ -518,5 +518,25 @@ describe Ci::CreatePipelineService do
end
end
end
context 'when pipelie is running for a tag' do
before do
allow_any_instance_of(Repository)
.to receive(:tag_exists?).and_return(false)
allow_any_instance_of(Repository)
.to receive(:tag_exists?).with('refs/tags/mytag').and_return(true)
config = YAML.dump(test: { script: 'test', only: ['branches'] },
deploy: { script: 'deploy', only: ['tags'] })
stub_ci_pipeline_yaml_file(config)
end
it 'creates a tagged pipeline' do
pipeline = execute_service(ref: 'mytag')
expect(pipeline.tag?).to be true
end
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment