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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
62e92031
Commit
62e92031
authored
Jan 10, 2019
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add specs for creating a bridge jobs from triggers
parent
c86015bf
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
67 additions
and
11 deletions
+67
-11
ee/lib/ee/gitlab/ci/config/entry/bridge.rb
ee/lib/ee/gitlab/ci/config/entry/bridge.rb
+27
-4
ee/spec/services/ci/create_pipeline_service_spec.rb
ee/spec/services/ci/create_pipeline_service_spec.rb
+29
-0
lib/gitlab/ci/pipeline/seed/build.rb
lib/gitlab/ci/pipeline/seed/build.rb
+7
-4
lib/gitlab/ci/pipeline/seed/stage.rb
lib/gitlab/ci/pipeline/seed/stage.rb
+1
-1
lib/gitlab/ci/yaml_processor.rb
lib/gitlab/ci/yaml_processor.rb
+3
-2
No files found.
ee/lib/ee/gitlab/ci/config/entry/bridge.rb
View file @
62e92031
...
...
@@ -13,7 +13,16 @@ module EE
include
::
Gitlab
::
Config
::
Entry
::
Configurable
include
::
Gitlab
::
Config
::
Entry
::
Attributable
ALLOWED_KEYS
=
%i[trigger]
.
freeze
ALLOWED_KEYS
=
%i[trigger stage allow_failure only except]
.
freeze
# TODO we probably need a common ancestor for a status / job
#
DEFAULT_ONLY_POLICY
=
{
refs:
%w(branches tags)
}.
freeze
DEFAULT_EXCEPT_POLICY
=
{
}.
freeze
validations
do
validates
:config
,
allowed_keys:
ALLOWED_KEYS
...
...
@@ -26,15 +35,29 @@ module EE
entry
:trigger
,
::
EE
::
Gitlab
::
Ci
::
Config
::
Entry
::
Trigger
,
description:
'CI/CD Bridge downstream trigger definition.'
helpers
:trigger
attributes
ALLOWED_KEYS
entry
:stage
,
::
Gitlab
::
Ci
::
Config
::
Entry
::
Stage
,
description:
'Pipeline stage this job will be executed into.'
entry
:only
,
::
Gitlab
::
Ci
::
Config
::
Entry
::
Policy
,
description:
'Refs policy this job will be executed for.'
entry
:except
,
::
Gitlab
::
Ci
::
Config
::
Entry
::
Policy
,
description:
'Refs policy this job will be executed for.'
helpers
*
ALLOWED_KEYS
attributes
*
ALLOWED_KEYS
def
name
@metadata
[
:name
]
end
def
value
{
name:
name
,
trigger:
trigger_value
}
{
name:
name
,
trigger:
trigger_value
,
ignore:
!!
allow_failure
,
stage:
stage_value
,
only:
DEFAULT_ONLY_POLICY
.
deep_merge
(
only_value
.
to_h
),
except:
DEFAULT_EXCEPT_POLICY
.
deep_merge
(
except_value
.
to_h
)
}
end
end
end
...
...
ee/spec/services/ci/create_pipeline_service_spec.rb
View file @
62e92031
...
...
@@ -68,6 +68,35 @@ describe Ci::CreatePipelineService, '#execute' do
end
end
describe
'cross-project pipeline triggers'
do
before
do
stub_feature_flags
(
cross_project_pipeline_triggers:
true
)
stub_ci_pipeline_yaml_file
<<~
YAML
test:
script: rspec
deploy:
stage: deploy
trigger: my/project
YAML
end
it
'creates bridge jobs correctly'
do
pipeline
=
create_pipeline!
test
=
pipeline
.
statuses
.
find_by
(
name:
'test'
)
bridge
=
pipeline
.
statuses
.
find_by
(
name:
'deploy'
)
expect
(
pipeline
).
to
be_persisted
expect
(
test
).
to
be_a
Ci
::
Build
expect
(
bridge
).
to
be_a
Ci
::
Bridge
expect
(
bridge
.
stage
).
to
eq
'deploy'
expect
(
pipeline
.
statuses
).
to
match_array
[
test
,
bridge
]
expect
(
bridge
.
options
).
to
eq
(
trigger:
{
project:
'my/project'
})
end
end
def
create_pipeline!
service
.
execute
(
:push
)
end
...
...
lib/gitlab/ci/pipeline/seed/build.rb
View file @
62e92031
...
...
@@ -4,6 +4,8 @@ module Gitlab
module
Ci
module
Pipeline
module
Seed
## TODO this should become Seed::Job now
#
class
Build
<
Seed
::
Base
include
Gitlab
::
Utils
::
StrongMemoize
...
...
@@ -13,6 +15,9 @@ module Gitlab
@pipeline
=
pipeline
@attributes
=
attributes
# TODO we should extract that
@type
=
attributes
.
dig
(
:options
,
:trigger
)
?
::
Ci
::
Bridge
:
::
Ci
::
Build
@only
=
Gitlab
::
Ci
::
Build
::
Policy
.
fabricate
(
attributes
.
delete
(
:only
))
@except
=
Gitlab
::
Ci
::
Build
::
Policy
...
...
@@ -35,13 +40,11 @@ module Gitlab
tag:
@pipeline
.
tag
,
trigger_request:
@pipeline
.
legacy_trigger
,
protected:
@pipeline
.
protected_ref?
)
)
.
compact
end
def
to_resource
strong_memoize
(
:resource
)
do
::
Ci
::
Build
.
new
(
attributes
)
end
strong_memoize
(
:resource
)
{
@type
.
new
(
attributes
)
}
end
end
end
...
...
lib/gitlab/ci/pipeline/seed/stage.rb
View file @
62e92031
...
...
@@ -39,7 +39,7 @@ module Gitlab
def
to_resource
strong_memoize
(
:stage
)
do
::
Ci
::
Stage
.
new
(
attributes
).
tap
do
|
stage
|
seeds
.
each
{
|
seed
|
stage
.
build
s
<<
seed
.
to_resource
}
seeds
.
each
{
|
seed
|
stage
.
statuse
s
<<
seed
.
to_resource
}
end
end
end
...
...
lib/gitlab/ci/yaml_processor.rb
View file @
62e92031
...
...
@@ -33,7 +33,7 @@ module Gitlab
{
stage_idx:
@stages
.
index
(
job
[
:stage
]),
stage:
job
[
:stage
],
tag_list:
job
[
:tags
]
||
[]
,
tag_list:
job
[
:tags
],
name:
job
[
:name
].
to_s
,
allow_failure:
job
[
:ignore
],
when:
job
[
:when
]
||
'on_success'
,
...
...
@@ -53,7 +53,8 @@ module Gitlab
retry:
job
[
:retry
],
parallel:
job
[
:parallel
],
instance:
job
[
:instance
],
start_in:
job
[
:start_in
]
start_in:
job
[
:start_in
],
trigger:
job
[
:trigger
]
}.
compact
}
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