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
Boxiang Sun
gitlab-ce
Commits
5d85a049
Commit
5d85a049
authored
Jan 10, 2019
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make it possible to fabricate CI/CD bridge jobs
parent
5692c282
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
70 additions
and
11 deletions
+70
-11
lib/gitlab/ci/pipeline/seed/build.rb
lib/gitlab/ci/pipeline/seed/build.rb
+9
-1
lib/gitlab/ci/pipeline/seed/stage.rb
lib/gitlab/ci/pipeline/seed/stage.rb
+7
-1
lib/gitlab/ci/yaml_processor.rb
lib/gitlab/ci/yaml_processor.rb
+3
-2
spec/lib/gitlab/ci/pipeline/seed/build_spec.rb
spec/lib/gitlab/ci/pipeline/seed/build_spec.rb
+39
-5
spec/lib/gitlab/ci/pipeline/seed/stage_spec.rb
spec/lib/gitlab/ci/pipeline/seed/stage_spec.rb
+12
-2
No files found.
lib/gitlab/ci/pipeline/seed/build.rb
View file @
5d85a049
...
@@ -38,8 +38,15 @@ module Gitlab
...
@@ -38,8 +38,15 @@ module Gitlab
)
)
end
end
def
bridge?
@attributes
.
to_h
.
dig
(
:options
,
:trigger
).
present?
end
def
to_resource
def
to_resource
strong_memoize
(
:resource
)
do
strong_memoize
(
:resource
)
do
if
bridge?
::
Ci
::
Bridge
.
new
(
attributes
)
else
::
Ci
::
Build
.
new
(
attributes
)
::
Ci
::
Build
.
new
(
attributes
)
end
end
end
end
...
@@ -47,4 +54,5 @@ module Gitlab
...
@@ -47,4 +54,5 @@ module Gitlab
end
end
end
end
end
end
end
end
end
lib/gitlab/ci/pipeline/seed/stage.rb
View file @
5d85a049
...
@@ -39,7 +39,13 @@ module Gitlab
...
@@ -39,7 +39,13 @@ module Gitlab
def
to_resource
def
to_resource
strong_memoize
(
:stage
)
do
strong_memoize
(
:stage
)
do
::
Ci
::
Stage
.
new
(
attributes
).
tap
do
|
stage
|
::
Ci
::
Stage
.
new
(
attributes
).
tap
do
|
stage
|
seeds
.
each
{
|
seed
|
stage
.
builds
<<
seed
.
to_resource
}
seeds
.
each
do
|
seed
|
if
seed
.
bridge?
stage
.
statuses
<<
seed
.
to_resource
else
stage
.
builds
<<
seed
.
to_resource
end
end
end
end
end
end
end
end
...
...
lib/gitlab/ci/yaml_processor.rb
View file @
5d85a049
...
@@ -33,7 +33,7 @@ module Gitlab
...
@@ -33,7 +33,7 @@ module Gitlab
{
stage_idx:
@stages
.
index
(
job
[
:stage
]),
{
stage_idx:
@stages
.
index
(
job
[
:stage
]),
stage:
job
[
:stage
],
stage:
job
[
:stage
],
tag_list:
job
[
:tags
]
||
[]
,
tag_list:
job
[
:tags
],
name:
job
[
:name
].
to_s
,
name:
job
[
:name
].
to_s
,
allow_failure:
job
[
:ignore
],
allow_failure:
job
[
:ignore
],
when:
job
[
:when
]
||
'on_success'
,
when:
job
[
:when
]
||
'on_success'
,
...
@@ -53,7 +53,8 @@ module Gitlab
...
@@ -53,7 +53,8 @@ module Gitlab
retry:
job
[
:retry
],
retry:
job
[
:retry
],
parallel:
job
[
:parallel
],
parallel:
job
[
:parallel
],
instance:
job
[
:instance
],
instance:
job
[
:instance
],
start_in:
job
[
:start_in
]
start_in:
job
[
:start_in
],
trigger:
job
[
:trigger
]
}.
compact
}
}.
compact
}
end
end
...
...
spec/lib/gitlab/ci/pipeline/seed/build_spec.rb
View file @
5d85a049
...
@@ -5,8 +5,7 @@ describe Gitlab::Ci::Pipeline::Seed::Build do
...
@@ -5,8 +5,7 @@ describe Gitlab::Ci::Pipeline::Seed::Build do
let
(
:pipeline
)
{
create
(
:ci_empty_pipeline
,
project:
project
)
}
let
(
:pipeline
)
{
create
(
:ci_empty_pipeline
,
project:
project
)
}
let
(
:attributes
)
do
let
(
:attributes
)
do
{
name:
'rspec'
,
{
name:
'rspec'
,
ref:
'master'
}
ref:
'master'
}
end
end
subject
do
subject
do
...
@@ -21,11 +20,46 @@ describe Gitlab::Ci::Pipeline::Seed::Build do
...
@@ -21,11 +20,46 @@ describe Gitlab::Ci::Pipeline::Seed::Build do
end
end
end
end
describe
'#bridge?'
do
context
'when job is a bridge'
do
let
(
:attributes
)
do
{
name:
'rspec'
,
ref:
'master'
,
options:
{
trigger:
'my/project'
}
}
end
it
{
is_expected
.
to
be_bridge
}
end
context
'when trigger definition is empty'
do
let
(
:attributes
)
do
{
name:
'rspec'
,
ref:
'master'
,
options:
{
trigger:
''
}
}
end
it
{
is_expected
.
not_to
be_bridge
}
end
context
'when job is not a bridge'
do
it
{
is_expected
.
not_to
be_bridge
}
end
end
describe
'#to_resource'
do
describe
'#to_resource'
do
context
'when job is not a bridge'
do
it
'returns a valid build resource'
do
it
'returns a valid build resource'
do
expect
(
subject
.
to_resource
).
to
be_a
(
::
Ci
::
Build
)
expect
(
subject
.
to_resource
).
to
be_a
(
::
Ci
::
Build
)
expect
(
subject
.
to_resource
).
to
be_valid
expect
(
subject
.
to_resource
).
to
be_valid
end
end
end
context
'when job is a bridge'
do
let
(
:attributes
)
do
{
name:
'rspec'
,
ref:
'master'
,
options:
{
trigger:
'my/project'
}
}
end
it
'returns a valid bridge resource'
do
expect
(
subject
.
to_resource
).
to
be_a
(
::
Ci
::
Bridge
)
expect
(
subject
.
to_resource
).
to
be_valid
end
end
it
'memoizes a resource object'
do
it
'memoizes a resource object'
do
build
=
subject
.
to_resource
build
=
subject
.
to_resource
...
...
spec/lib/gitlab/ci/pipeline/seed/stage_spec.rb
View file @
5d85a049
...
@@ -62,8 +62,18 @@ describe Gitlab::Ci::Pipeline::Seed::Stage do
...
@@ -62,8 +62,18 @@ describe Gitlab::Ci::Pipeline::Seed::Stage do
expect
(
subject
.
seeds
.
map
(
&
:attributes
)).
to
all
(
include
(
ref:
'master'
))
expect
(
subject
.
seeds
.
map
(
&
:attributes
)).
to
all
(
include
(
ref:
'master'
))
expect
(
subject
.
seeds
.
map
(
&
:attributes
)).
to
all
(
include
(
tag:
false
))
expect
(
subject
.
seeds
.
map
(
&
:attributes
)).
to
all
(
include
(
tag:
false
))
expect
(
subject
.
seeds
.
map
(
&
:attributes
)).
to
all
(
include
(
project:
pipeline
.
project
))
expect
(
subject
.
seeds
.
map
(
&
:attributes
)).
to
all
(
include
(
project:
pipeline
.
project
))
end
context
'when a legacy trigger exists'
do
before
do
create
(
:ci_trigger_request
,
pipeline:
pipeline
)
end
it
'returns build seeds including legacy trigger'
do
expect
(
pipeline
.
legacy_trigger
).
not_to
be_nil
expect
(
subject
.
seeds
.
map
(
&
:attributes
))
expect
(
subject
.
seeds
.
map
(
&
:attributes
))
.
to
all
(
include
(
trigger_request:
pipeline
.
trigger_requests
.
first
))
.
to
all
(
include
(
trigger_request:
pipeline
.
legacy_trigger
))
end
end
end
context
'when a ref is protected'
do
context
'when a ref is protected'
do
...
...
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