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
1c2530de
Commit
1c2530de
authored
Mar 23, 2018
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Expose evaluable variables method from build object
parent
bf59ed3c
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
49 additions
and
13 deletions
+49
-13
app/models/ci/build.rb
app/models/ci/build.rb
+13
-2
lib/gitlab/ci/build/policy/variables.rb
lib/gitlab/ci/build/policy/variables.rb
+2
-3
spec/lib/gitlab/ci/pipeline/chain/populate_spec.rb
spec/lib/gitlab/ci/pipeline/chain/populate_spec.rb
+6
-1
spec/models/ci/build_spec.rb
spec/models/ci/build_spec.rb
+28
-7
No files found.
app/models/ci/build.rb
View file @
1c2530de
...
@@ -244,13 +244,24 @@ module Ci
...
@@ -244,13 +244,24 @@ module Ci
Gitlab
::
Utils
.
slugify
(
ref
.
to_s
)
Gitlab
::
Utils
.
slugify
(
ref
.
to_s
)
end
end
##
# Variables whose value does not depend on environment
# Variables whose value does not depend on environment
#
def
simple_variables
def
simple_variables
variables
(
environment:
nil
)
variables
(
environment:
nil
)
end
end
# All variables, including those dependent on environment, which could
##
# 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.
# contain unexpanded variables.
#
def
variables
(
environment:
persisted_environment
)
def
variables
(
environment:
persisted_environment
)
collection
=
Gitlab
::
Ci
::
Variables
::
Collection
.
new
.
tap
do
|
variables
|
collection
=
Gitlab
::
Ci
::
Variables
::
Collection
.
new
.
tap
do
|
variables
|
variables
.
concat
(
predefined_variables
)
variables
.
concat
(
predefined_variables
)
...
...
lib/gitlab/ci/build/policy/variables.rb
View file @
1c2530de
...
@@ -8,9 +8,8 @@ module Gitlab
...
@@ -8,9 +8,8 @@ module Gitlab
end
end
def
satisfied_by?
(
pipeline
,
seed
)
def
satisfied_by?
(
pipeline
,
seed
)
variables
=
Gitlab
::
Ci
::
Variables
::
Collection
variables
=
seed
.
to_resource
.
new
(
seed
.
to_resource
.
simple_variables
)
.
evaluable_variables
.
to_hash
.
to_hash
statements
=
@expressions
.
map
do
|
statement
|
statements
=
@expressions
.
map
do
|
statement
|
::
Gitlab
::
Ci
::
Pipeline
::
Expression
::
Statement
::
Gitlab
::
Ci
::
Pipeline
::
Expression
::
Statement
...
...
spec/lib/gitlab/ci/pipeline/chain/populate_spec.rb
View file @
1c2530de
...
@@ -6,7 +6,8 @@ describe Gitlab::Ci::Pipeline::Chain::Populate do
...
@@ -6,7 +6,8 @@ describe Gitlab::Ci::Pipeline::Chain::Populate do
let
(
:pipeline
)
do
let
(
:pipeline
)
do
build
(
:ci_pipeline_with_one_job
,
project:
project
,
build
(
:ci_pipeline_with_one_job
,
project:
project
,
ref:
'master'
)
ref:
'master'
,
user:
user
)
end
end
let
(
:command
)
do
let
(
:command
)
do
...
@@ -42,6 +43,10 @@ describe Gitlab::Ci::Pipeline::Chain::Populate do
...
@@ -42,6 +43,10 @@ describe Gitlab::Ci::Pipeline::Chain::Populate do
expect
(
pipeline
.
stages
.
first
.
builds
).
to
be_one
expect
(
pipeline
.
stages
.
first
.
builds
).
to
be_one
expect
(
pipeline
.
stages
.
first
.
builds
.
first
).
not_to
be_persisted
expect
(
pipeline
.
stages
.
first
.
builds
.
first
).
not_to
be_persisted
end
end
it
'correctly assigns user'
do
expect
(
pipeline
.
builds
).
to
all
(
have_attributes
(
user:
user
))
end
end
end
context
'when pipeline is empty'
do
context
'when pipeline is empty'
do
...
...
spec/models/ci/build_spec.rb
View file @
1c2530de
...
@@ -1978,6 +1978,27 @@ describe Ci::Build do
...
@@ -1978,6 +1978,27 @@ describe Ci::Build do
end
end
end
end
context
'when build has not been persisted yet'
do
let
(
:build
)
do
described_class
.
new
(
name:
'rspec'
,
stage:
'test'
,
ref:
'feature'
,
project:
project
,
pipeline:
pipeline
)
end
it
'returns static predefined variables'
do
expect
(
build
.
variables
.
size
).
to
be
>=
28
expect
(
build
.
variables
)
.
to
include
(
key:
'CI_COMMIT_REF_NAME'
,
value:
'feature'
,
public:
true
)
expect
(
build
).
not_to
be_persisted
end
end
end
describe
'#evaluable_variables'
do
context
'when build has not been persisted yet'
do
context
'when build has not been persisted yet'
do
let
(
:build
)
do
let
(
:build
)
do
described_class
.
new
(
described_class
.
new
(
...
@@ -1993,9 +2014,8 @@ describe Ci::Build do
...
@@ -1993,9 +2014,8 @@ describe Ci::Build do
expect
(
build
).
to
be_valid
expect
(
build
).
to
be_valid
expect
(
build
).
not_to
be_persisted
expect
(
build
).
not_to
be_persisted
variables
=
build
.
variables
variables
=
build
.
evaluable_
variables
expect
(
variables
.
size
).
to
be
>=
28
expect
(
build
).
not_to
be_persisted
expect
(
build
).
not_to
be_persisted
end
end
...
@@ -2006,13 +2026,14 @@ describe Ci::Build do
...
@@ -2006,13 +2026,14 @@ describe Ci::Build do
CI_COMMIT_REF_SLUG
CI_COMMIT_REF_SLUG
CI_JOB_STAGE]
CI_JOB_STAGE]
build
.
variables
.
map
{
|
var
|
var
.
fetch
(
:key
)
}.
tap
do
|
names
|
variables
=
build
.
evaluable_variables
variables
.
map
{
|
env
|
env
[
:key
]
}.
tap
do
|
names
|
expect
(
names
).
to
include
(
*
keys
)
expect
(
names
).
to
include
(
*
keys
)
end
end
expect
(
build
.
variables
).
to
include
(
key:
'CI_COMMIT_REF_NAME'
,
expect
(
variables
)
value:
'feature'
,
.
to
include
(
key:
'CI_COMMIT_REF_NAME'
,
value:
'feature'
,
public:
true
)
public:
true
)
end
end
it
'does not return prohibited variables'
do
it
'does not return prohibited variables'
do
...
@@ -2025,7 +2046,7 @@ describe Ci::Build do
...
@@ -2025,7 +2046,7 @@ describe Ci::Build do
CI_REPOSITORY_URL
CI_REPOSITORY_URL
CI_ENVIRONMENT_URL]
CI_ENVIRONMENT_URL]
build
.
variables
.
map
{
|
var
|
var
.
fetch
(
:key
)
}.
tap
do
|
names
|
build
.
evaluable_variables
.
map
{
|
env
|
env
[
:key
]
}.
tap
do
|
names
|
expect
(
names
).
not_to
include
(
*
keys
)
expect
(
names
).
not_to
include
(
*
keys
)
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