Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
b30e0e06
Commit
b30e0e06
authored
Dec 08, 2017
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix invalid pipeline build chain tag evaluation
parent
fe62860e
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
69 additions
and
8 deletions
+69
-8
lib/gitlab/ci/pipeline/chain/build.rb
lib/gitlab/ci/pipeline/chain/build.rb
+4
-2
lib/gitlab/ci/pipeline/chain/helpers.rb
lib/gitlab/ci/pipeline/chain/helpers.rb
+10
-4
spec/lib/gitlab/ci/pipeline/chain/build_spec.rb
spec/lib/gitlab/ci/pipeline/chain/build_spec.rb
+35
-2
spec/services/ci/create_pipeline_service_spec.rb
spec/services/ci/create_pipeline_service_spec.rb
+20
-0
No files found.
lib/gitlab/ci/pipeline/chain/build.rb
View file @
b30e0e06
...
@@ -3,8 +3,6 @@ module Gitlab
...
@@ -3,8 +3,6 @@ module Gitlab
module
Pipeline
module
Pipeline
module
Chain
module
Chain
class
Build
<
Chain
::
Base
class
Build
<
Chain
::
Base
include
Chain
::
Helpers
def
perform!
def
perform!
@pipeline
.
assign_attributes
(
@pipeline
.
assign_attributes
(
source:
@command
.
source
,
source:
@command
.
source
,
...
@@ -51,6 +49,10 @@ module Gitlab
...
@@ -51,6 +49,10 @@ module Gitlab
def
protected_ref?
def
protected_ref?
@project
.
protected_for?
(
ref
)
@project
.
protected_for?
(
ref
)
end
end
def
tag_exists?
project
.
repository
.
tag_exists?
(
ref
)
end
end
end
end
end
end
end
...
...
lib/gitlab/ci/pipeline/chain/helpers.rb
View file @
b30e0e06
...
@@ -3,16 +3,22 @@ module Gitlab
...
@@ -3,16 +3,22 @@ module Gitlab
module
Pipeline
module
Pipeline
module
Chain
module
Chain
module
Helpers
module
Helpers
include
Gitlab
::
Utils
::
StrongMemoize
def
branch_exists?
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
end
def
tag_exists?
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
end
def
error
(
message
)
def
error
(
message
)
...
...
spec/lib/gitlab/ci/pipeline/chain/build_spec.rb
View file @
b30e0e06
...
@@ -21,31 +21,64 @@ describe Gitlab::Ci::Pipeline::Chain::Build do
...
@@ -21,31 +21,64 @@ describe Gitlab::Ci::Pipeline::Chain::Build do
before
do
before
do
stub_repository_ci_yaml_file
(
sha:
anything
)
stub_repository_ci_yaml_file
(
sha:
anything
)
step
.
perform!
end
end
it
'never breaks the chain'
do
it
'never breaks the chain'
do
step
.
perform!
expect
(
step
.
break?
).
to
be
false
expect
(
step
.
break?
).
to
be
false
end
end
it
'fills pipeline object with data'
do
it
'fills pipeline object with data'
do
step
.
perform!
expect
(
pipeline
.
sha
).
not_to
be_empty
expect
(
pipeline
.
sha
).
not_to
be_empty
expect
(
pipeline
.
sha
).
to
eq
project
.
commit
.
id
expect
(
pipeline
.
sha
).
to
eq
project
.
commit
.
id
expect
(
pipeline
.
ref
).
to
eq
'master'
expect
(
pipeline
.
ref
).
to
eq
'master'
expect
(
pipeline
.
tag
).
to
be
false
expect
(
pipeline
.
user
).
to
eq
user
expect
(
pipeline
.
user
).
to
eq
user
expect
(
pipeline
.
project
).
to
eq
project
expect
(
pipeline
.
project
).
to
eq
project
end
end
it
'sets a valid config source'
do
it
'sets a valid config source'
do
step
.
perform!
expect
(
pipeline
.
repository_source?
).
to
be
true
expect
(
pipeline
.
repository_source?
).
to
be
true
end
end
it
'returns a valid pipeline'
do
it
'returns a valid pipeline'
do
step
.
perform!
expect
(
pipeline
).
to
be_valid
expect
(
pipeline
).
to
be_valid
end
end
it
'does not persist a pipeline'
do
it
'does not persist a pipeline'
do
step
.
perform!
expect
(
pipeline
).
not_to
be_persisted
expect
(
pipeline
).
not_to
be_persisted
end
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
end
spec/services/ci/create_pipeline_service_spec.rb
View file @
b30e0e06
...
@@ -518,5 +518,25 @@ describe Ci::CreatePipelineService do
...
@@ -518,5 +518,25 @@ describe Ci::CreatePipelineService do
end
end
end
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
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment