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
Jérome Perrin
gitlab-ce
Commits
da6bfd9b
Commit
da6bfd9b
authored
Mar 27, 2018
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Decouple build variables from persisted environment
parent
dbe9e0df
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
47 additions
and
34 deletions
+47
-34
app/models/ci/build.rb
app/models/ci/build.rb
+42
-28
lib/gitlab/ci/build/policy/variables.rb
lib/gitlab/ci/build/policy/variables.rb
+1
-2
spec/models/ci/build_spec.rb
spec/models/ci/build_spec.rb
+4
-4
No files found.
app/models/ci/build.rb
View file @
da6bfd9b
...
...
@@ -23,7 +23,9 @@ module Ci
has_one
:job_artifacts_metadata
,
->
{
where
(
file_type:
Ci
::
JobArtifact
.
file_types
[
:metadata
])
},
class_name:
'Ci::JobArtifact'
,
inverse_of: :job
,
foreign_key: :job_id
has_one
:job_artifacts_trace
,
->
{
where
(
file_type:
Ci
::
JobArtifact
.
file_types
[
:trace
])
},
class_name:
'Ci::JobArtifact'
,
inverse_of: :job
,
foreign_key: :job_id
# The "environment" field for builds is a String, and is the unexpanded name
##
# The "environment" field for builds is a String, and is the unexpanded name!
#
def
persisted_environment
@persisted_environment
||=
Environment
.
find_by
(
name:
expanded_environment_name
,
...
...
@@ -198,7 +200,9 @@ module Ci
end
def
expanded_environment_name
ExpandVariables
.
expand
(
environment
,
simple_variables
)
if
environment
if
has_environment?
ExpandVariables
.
expand
(
environment
,
simple_variables
)
end
end
def
has_environment?
...
...
@@ -249,41 +253,46 @@ module Ci
end
##
# Variables whose value does not depend on environment
#
def
simple_variables
variables
(
environment:
nil
)
end
##
# Variables that are available for evaluation using variables policy.
#
def
evaluable_variables
Gitlab
::
Ci
::
Variables
::
Collection
.
new
.
concat
(
simple_variables
)
end
## All variables, including those dependent on environment, which could
# contain unexpanded variables.
# Variables in the environment name scope.
#
def
variables
(
environment:
persisted_environment
)
collection
=
Gitlab
::
Ci
::
Variables
::
Collection
.
new
.
tap
do
|
variables
|
def
scoped_variables
(
environment:
expanded_environment_name
)
Gitlab
::
Ci
::
Variables
::
Collection
.
new
.
tap
do
|
variables
|
variables
.
concat
(
predefined_variables
)
variables
.
concat
(
project
.
predefined_variables
)
variables
.
concat
(
pipeline
.
predefined_variables
)
variables
.
concat
(
runner
.
predefined_variables
)
if
runner
variables
.
concat
(
project
.
deployment_variables
(
environment:
environment
))
if
has_environment?
variables
.
concat
(
project
.
deployment_variables
(
environment:
environment
))
if
environment
variables
.
concat
(
yaml_variables
)
variables
.
concat
(
user_variables
)
variables
.
concat
(
project
.
group
.
secret_variables_for
(
ref
,
project
))
if
project
.
group
variables
.
concat
(
secret_variables
(
environment:
environment
))
variables
.
concat
(
secret_group_variables
)
variables
.
concat
(
secret_
project_
variables
(
environment:
environment
))
variables
.
concat
(
trigger_request
.
user_variables
)
if
trigger_request
variables
.
concat
(
pipeline
.
variables
)
variables
.
concat
(
pipeline
.
pipeline_schedule
.
job_variables
)
if
pipeline
.
pipeline_schedule
variables
.
concat
(
persisted_environment_variables
)
if
environment
end
end
collection
.
to_runner_variables
##
# Variables that do not depend on the environment name.
#
def
simple_variables
scoped_variables
(
environment:
nil
).
to_runner_variables
end
##
# All variables, including persisted environment variables.
#
def
variables
scoped_variables
.
concat
(
persisted_environment_variables
)
.
to_runner_variables
end
##
# TODO, add specs
#
def
variables_hash
scoped_variables
.
to_hash
end
def
features
...
...
@@ -454,9 +463,14 @@ module Ci
end
end
def
secret_variables
(
environment:
persisted_environment
)
def
secret_group_variables
return
[]
unless
project
.
group
project
.
group
.
secret_variables_for
(
ref
,
project
)
end
def
secret_project_variables
(
environment:
persisted_environment
)
project
.
secret_variables_for
(
ref:
ref
,
environment:
environment
)
.
map
(
&
:to_runner_variable
)
end
def
steps
...
...
@@ -580,7 +594,7 @@ module Ci
def
persisted_environment_variables
Gitlab
::
Ci
::
Variables
::
Collection
.
new
.
tap
do
|
variables
|
return
variables
unless
persisted
_environment
return
variables
unless
persisted
?
&&
persisted_environment
.
present?
variables
.
concat
(
persisted_environment
.
predefined_variables
)
...
...
lib/gitlab/ci/build/policy/variables.rb
View file @
da6bfd9b
...
...
@@ -8,8 +8,7 @@ module Gitlab
end
def
satisfied_by?
(
pipeline
,
seed
)
variables
=
seed
.
to_resource
.
evaluable_variables
.
to_hash
variables
=
seed
.
to_resource
.
variables_hash
statements
=
@expressions
.
map
do
|
statement
|
::
Gitlab
::
Ci
::
Pipeline
::
Expression
::
Statement
...
...
spec/models/ci/build_spec.rb
View file @
da6bfd9b
...
...
@@ -1998,7 +1998,7 @@ describe Ci::Build do
end
end
describe
'#
evaluable
_variables'
do
describe
'#
scoped
_variables'
do
context
'when build has not been persisted yet'
do
let
(
:build
)
do
described_class
.
new
(
...
...
@@ -2014,7 +2014,7 @@ describe Ci::Build do
expect
(
build
).
to
be_valid
expect
(
build
).
not_to
be_persisted
variables
=
build
.
evaluable
_variables
build
.
scoped
_variables
expect
(
build
).
not_to
be_persisted
end
...
...
@@ -2026,7 +2026,7 @@ describe Ci::Build do
CI_COMMIT_REF_SLUG
CI_JOB_STAGE]
variables
=
build
.
evaluable
_variables
variables
=
build
.
scoped
_variables
variables
.
map
{
|
env
|
env
[
:key
]
}.
tap
do
|
names
|
expect
(
names
).
to
include
(
*
keys
)
...
...
@@ -2046,7 +2046,7 @@ describe Ci::Build do
CI_REPOSITORY_URL
CI_ENVIRONMENT_URL]
build
.
evaluable
_variables
.
map
{
|
env
|
env
[
:key
]
}.
tap
do
|
names
|
build
.
scoped
_variables
.
map
{
|
env
|
env
[
:key
]
}.
tap
do
|
names
|
expect
(
names
).
not_to
include
(
*
keys
)
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