BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
b94db067
Commit
b94db067
authored
Mar 12, 2018
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use variables collection as build predefined variables
parent
5ed8286e
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
43 additions
and
29 deletions
+43
-29
build.rb
app/models/ci/build.rb
+19
-17
has_variable.rb
app/models/concerns/has_variable.rb
+5
-1
project.rb
app/models/project.rb
+11
-9
collection.rb
lib/gitlab/ci/variables/collection.rb
+5
-1
item.rb
lib/gitlab/ci/variables/collection/item.rb
+3
-1
No files found.
app/models/ci/build.rb
View file @
b94db067
...
@@ -252,23 +252,25 @@ module Ci
...
@@ -252,23 +252,25 @@ module Ci
# All variables, including those dependent on environment, which could
# 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
)
variables
=
predefined_variables
collection
=
Gitlab
::
Ci
::
Variables
::
Collection
.
new
.
tap
do
|
variables
|
variables
+=
project
.
predefined_variables
variables
.
concat
(
predefined_variables
)
variables
+=
pipeline
.
predefined_variables
variables
.
concat
(
project
.
predefined_variables
)
variables
+=
runner
.
predefined_variables
if
runner
variables
.
concat
(
pipeline
.
predefined_variables
)
variables
+=
project
.
container_registry_variables
variables
.
concat
(
runner
.
predefined_variables
)
if
runner
variables
+=
project
.
deployment_variables
if
has_environment?
variables
.
concat
(
project
.
container_registry_variables
)
variables
+=
project
.
auto_devops_variables
variables
.
concat
(
project
.
deployment_variables
)
if
has_environment?
variables
+=
yaml_variables
variables
.
concat
(
project
.
auto_devops_variables
)
variables
+=
user_variables
variables
.
concat
(
yaml_variables
)
variables
+=
project
.
group
.
secret_variables_for
(
ref
,
project
).
map
(
&
:to_runner_variable
)
if
project
.
group
variables
.
concat
(
user_variables
)
variables
+=
secret_variables
(
environment:
environment
)
variables
.
concat
(
project
.
group
.
secret_variables_for
(
ref
,
project
).
map
(
&
:to_runner_variable
))
if
project
.
group
variables
+=
trigger_request
.
user_variables
if
trigger_request
variables
.
concat
(
secret_variables
(
environment:
environment
))
variables
+=
pipeline
.
variables
.
map
(
&
:to_runner_variable
)
variables
.
concat
(
trigger_request
.
user_variables
)
if
trigger_request
variables
+=
pipeline
.
pipeline_schedule
.
job_variables
if
pipeline
.
pipeline_schedule
variables
.
concat
(
pipeline
.
variables
)
variables
+=
persisted_environment_variables
if
environment
variables
.
concat
(
pipeline
.
pipeline_schedule
.
job_variables
)
if
pipeline
.
pipeline_schedule
variables
.
concat
(
persisted_environment_variables
)
if
environment
variables
end
collection
.
to_runner_variables
end
end
def
features
def
features
...
...
app/models/concerns/has_variable.rb
View file @
b94db067
...
@@ -20,8 +20,12 @@ module HasVariable
...
@@ -20,8 +20,12 @@ module HasVariable
super
(
new_key
.
to_s
.
strip
)
super
(
new_key
.
to_s
.
strip
)
end
end
def
to_
runner_variable
def
to_
hash
{
key:
key
,
value:
value
,
public:
false
}
{
key:
key
,
value:
value
,
public:
false
}
end
end
def
to_runner_variable
to_hash
end
end
end
end
end
app/models/project.rb
View file @
b94db067
...
@@ -1571,15 +1571,17 @@ class Project < ActiveRecord::Base
...
@@ -1571,15 +1571,17 @@ class Project < ActiveRecord::Base
end
end
def
predefined_variables
def
predefined_variables
[
visibility
=
Gitlab
::
VisibilityLevel
.
string_level
(
visibility_level
)
{
key:
'CI_PROJECT_ID'
,
value:
id
.
to_s
,
public:
true
},
{
key:
'CI_PROJECT_NAME'
,
value:
path
,
public:
true
},
Gitlab
::
Ci
::
Variables
::
Collection
.
new
.
tap
do
|
variables
|
{
key:
'CI_PROJECT_PATH'
,
value:
full_path
,
public:
true
},
variables
.
append
(
key:
'CI_PROJECT_ID'
,
value:
id
.
to_s
,
public:
true
)
{
key:
'CI_PROJECT_PATH_SLUG'
,
value:
full_path_slug
,
public:
true
},
variables
.
append
(
key:
'CI_PROJECT_NAME'
,
value:
path
,
public:
true
)
{
key:
'CI_PROJECT_NAMESPACE'
,
value:
namespace
.
full_path
,
public:
true
},
variables
.
append
(
key:
'CI_PROJECT_PATH'
,
value:
full_path
,
public:
true
)
{
key:
'CI_PROJECT_URL'
,
value:
web_url
,
public:
true
},
variables
.
append
(
key:
'CI_PROJECT_PATH_SLUG'
,
value:
full_path_slug
,
public:
true
)
{
key:
'CI_PROJECT_VISIBILITY'
,
value:
Gitlab
::
VisibilityLevel
.
string_level
(
visibility_level
),
public:
true
}
variables
.
append
(
key:
'CI_PROJECT_NAMESPACE'
,
value:
namespace
.
full_path
,
public:
true
)
]
variables
.
append
(
key:
'CI_PROJECT_URL'
,
value:
web_url
,
public:
true
)
variables
.
append
(
key:
'CI_PROJECT_VISIBILITY'
,
value:
visibility
,
public:
true
)
end
end
end
def
container_registry_variables
def
container_registry_variables
...
...
lib/gitlab/ci/variables/collection.rb
View file @
b94db067
...
@@ -7,13 +7,17 @@ module Gitlab
...
@@ -7,13 +7,17 @@ module Gitlab
def
initialize
(
variables
=
[])
def
initialize
(
variables
=
[])
@variables
=
[]
@variables
=
[]
variables
.
each
{
|
variable
|
append
(
variable
)
}
variables
.
each
{
|
variable
|
self
.
append
(
variable
)
}
end
end
def
append
(
resource
)
def
append
(
resource
)
@variables
.
append
(
Collection
::
Item
.
fabricate
(
resource
))
@variables
.
append
(
Collection
::
Item
.
fabricate
(
resource
))
end
end
def
concat
(
resources
)
resources
.
each
{
|
variable
|
self
.
append
(
variable
)
}
end
def
each
def
each
@variables
.
each
{
|
variable
|
yield
variable
}
@variables
.
each
{
|
variable
|
yield
variable
}
end
end
...
...
lib/gitlab/ci/variables/collection/item.rb
View file @
b94db067
...
@@ -33,10 +33,12 @@ module Gitlab
...
@@ -33,10 +33,12 @@ module Gitlab
self
.
new
(
resource
)
self
.
new
(
resource
)
when
::
Ci
::
Variable
when
::
Ci
::
Variable
self
.
new
(
resource
.
to_hash
)
self
.
new
(
resource
.
to_hash
)
when
::
Ci
::
PipelineVariable
self
.
new
(
resource
.
to_hash
)
when
self
when
self
resource
.
dup
resource
.
dup
else
else
raise
ArgumentError
,
'Unknown CI/CD variable resource!'
raise
ArgumentError
,
"Unknown `
#{
resource
.
class
}
` variable resource!"
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