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
ef378067
Commit
ef378067
authored
May 28, 2019
by
Grzegorz Bizon
Committed by
Douglas Barbosa Alexandre
May 28, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Expand pipeline variables passed downstream
parent
5f32de64
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
88 additions
and
1 deletion
+88
-1
doc/ci/multi_project_pipelines.md
doc/ci/multi_project_pipelines.md
+28
-0
ee/app/models/ee/ci/bridge.rb
ee/app/models/ee/ci/bridge.rb
+5
-1
ee/changelogs/unreleased/feature-gb-expand-pipeline-variables-passed-downstream.yml
...eature-gb-expand-pipeline-variables-passed-downstream.yml
+5
-0
ee/spec/models/ci/bridge_spec.rb
ee/spec/models/ci/bridge_spec.rb
+22
-0
ee/spec/services/ci/create_cross_project_pipeline_service_spec.rb
...services/ci/create_cross_project_pipeline_service_spec.rb
+28
-0
No files found.
doc/ci/multi_project_pipelines.md
View file @
ef378067
...
...
@@ -134,6 +134,34 @@ staging:
The
`ENVIRONMENT`
variable will be passed to every job defined in a downstream
pipeline. It will be available as an environment variable when GitLab Runner picks a job.
In the following configuration, the
`MY_VARIABLE`
variable will be passed
downstream, because jobs inherit variables declared in top-level
`variables`
:
```
yaml
variables
:
MY_VARIABLE
:
my-value
my-pipeline
:
variables
:
ENVIRONMENT
:
something
trigger
:
my/project
```
You might want to pass some information about the upstream pipeline using, for
example, predefined variables. In order to do that, you can use interpolation
to pass any variable. For example:
```
yaml
my-pipeline
:
variables
:
UPSTREAM_BRANCH
:
$CI_COMMIT_REF_NAME
trigger
:
my/project
```
In this scenario, the
`UPSTREAM_BRANCH`
variable with a value related to the
upstream pipeline will be passed to a
`downstream`
job, and will be available
within the context of all downstream builds.
### Limitations
Because bridge jobs are a little different to regular jobs, it is not
...
...
ee/app/models/ee/ci/bridge.rb
View file @
ef378067
...
...
@@ -44,7 +44,11 @@ module EE
end
def
downstream_variables
yaml_variables
.
to_a
.
map
{
|
hash
|
hash
.
except
(
:public
)
}
scoped_variables
.
to_runner_variables
.
yield_self
do
|
all_variables
|
yaml_variables
.
to_a
.
map
do
|
hash
|
{
key:
hash
[
:key
],
value:
::
ExpandVariables
.
expand
(
hash
[
:value
],
all_variables
)
}
end
end
end
end
end
...
...
ee/changelogs/unreleased/feature-gb-expand-pipeline-variables-passed-downstream.yml
0 → 100644
View file @
ef378067
---
title
:
Expand pipeline variables passed downstream
merge_request
:
13197
author
:
type
:
added
ee/spec/models/ci/bridge_spec.rb
View file @
ef378067
...
...
@@ -82,6 +82,28 @@ describe Ci::Bridge do
expect
(
bridge
.
downstream_variables
)
.
to
include
(
key:
'BRIDGE'
,
value:
'cross'
)
end
context
'when using variables interpolation'
do
before
do
bridge
.
yaml_variables
<<
{
key:
'EXPANDED'
,
value:
'$BRIDGE-bridge'
,
public:
true
}
end
it
'correctly expands variables with interpolation'
do
expect
(
bridge
.
downstream_variables
)
.
to
include
(
key:
'EXPANDED'
,
value:
'cross-bridge'
)
end
end
context
'when recursive interpolation has been used'
do
before
do
bridge
.
yaml_variables
<<
{
key:
'EXPANDED'
,
value:
'$EXPANDED'
,
public:
true
}
end
it
'does not expand variable recursively'
do
expect
(
bridge
.
downstream_variables
)
.
to
include
(
key:
'EXPANDED'
,
value:
'$EXPANDED'
)
end
end
end
describe
'metadata support'
do
...
...
ee/spec/services/ci/create_cross_project_pipeline_service_spec.rb
View file @
ef378067
...
...
@@ -154,5 +154,33 @@ describe Ci::CreateCrossProjectPipelineService, '#execute' do
.
to
have_attributes
(
key:
'BRIDGE'
,
value:
'var'
)
end
end
context
'when pipeline variables are defined'
do
before
do
upstream_pipeline
.
variables
.
create
(
key:
'PIPELINE_VARIABLE'
,
value:
'my-value'
)
end
it
'does not pass pipeline variables directly downstream'
do
pipeline
=
service
.
execute
(
bridge
)
pipeline
.
variables
.
map
(
&
:key
).
tap
do
|
variables
|
expect
(
variables
).
not_to
include
'PIPELINE_VARIABLE'
end
end
context
'when using YAML variables interpolation'
do
before
do
bridge
.
yaml_variables
=
[{
key:
'BRIDGE'
,
value:
'$PIPELINE_VARIABLE-var'
,
public:
true
}]
end
it
'makes it possible to pass pipeline variable downstream'
do
pipeline
=
service
.
execute
(
bridge
)
pipeline
.
variables
.
find_by
(
key:
'BRIDGE'
).
tap
do
|
variable
|
expect
(
variable
.
value
).
to
eq
'my-value-var'
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