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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-ce
Commits
b7946b50
Commit
b7946b50
authored
8 years ago
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Read job variables directly from gitlab CI config
parent
b578fbfb
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
38 additions
and
25 deletions
+38
-25
app/models/ci/build.rb
app/models/ci/build.rb
+6
-2
lib/ci/gitlab_ci_yaml_processor.rb
lib/ci/gitlab_ci_yaml_processor.rb
+10
-2
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
+2
-2
spec/models/build_spec.rb
spec/models/build_spec.rb
+9
-13
spec/support/gitlab_stubs/gitlab_ci.yml
spec/support/gitlab_stubs/gitlab_ci.yml
+11
-6
No files found.
app/models/ci/build.rb
View file @
b7946b50
...
@@ -381,8 +381,12 @@ module Ci
...
@@ -381,8 +381,12 @@ module Ci
end
end
def
job_yaml_variables
def
job_yaml_variables
options
[
:variables
].
to_h
.
map
do
|
key
,
value
|
if
commit
.
config_processor
{
key:
key
,
value:
value
,
public:
true
}
commit
.
config_processor
.
job_variables
(
name
).
map
do
|
key
,
value
|
{
key:
key
,
value:
value
,
public:
true
}
end
else
[]
end
end
end
end
...
...
This diff is collapsed.
Click to expand it.
lib/ci/gitlab_ci_yaml_processor.rb
View file @
b7946b50
...
@@ -9,7 +9,7 @@ module Ci
...
@@ -9,7 +9,7 @@ module Ci
:allow_failure
,
:type
,
:stage
,
:when
,
:artifacts
,
:cache
,
:allow_failure
,
:type
,
:stage
,
:when
,
:artifacts
,
:cache
,
:dependencies
,
:variables
]
:dependencies
,
:variables
]
attr_reader
:before_script
,
:image
,
:services
,
:
variables
,
:
path
,
:cache
attr_reader
:before_script
,
:image
,
:services
,
:path
,
:cache
def
initialize
(
config
,
path
=
nil
)
def
initialize
(
config
,
path
=
nil
)
@config
=
YAML
.
safe_load
(
config
,
[
Symbol
],
[],
true
)
@config
=
YAML
.
safe_load
(
config
,
[
Symbol
],
[],
true
)
...
@@ -40,6 +40,15 @@ module Ci
...
@@ -40,6 +40,15 @@ module Ci
@stages
||
DEFAULT_STAGES
@stages
||
DEFAULT_STAGES
end
end
def
variables
@variables
end
def
job_variables
(
name
)
job
=
@jobs
[
name
.
to_sym
]
job
?
job
[
:variables
]
:
[]
end
private
private
def
initial_parsing
def
initial_parsing
...
@@ -85,7 +94,6 @@ module Ci
...
@@ -85,7 +94,6 @@ module Ci
artifacts:
job
[
:artifacts
],
artifacts:
job
[
:artifacts
],
cache:
job
[
:cache
]
||
@cache
,
cache:
job
[
:cache
]
||
@cache
,
dependencies:
job
[
:dependencies
],
dependencies:
job
[
:dependencies
],
variables:
job
[
:variables
],
}.
compact
}.
compact
}
}
end
end
...
...
This diff is collapsed.
Click to expand it.
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
View file @
b7946b50
...
@@ -374,10 +374,10 @@ module Ci
...
@@ -374,10 +374,10 @@ module Ci
})
})
end
end
it
'
appends job variable to job attribut
es'
do
it
'
returns job variabl
es'
do
config
=
GitlabCiYamlProcessor
.
new
(
yaml_config
,
path
)
config
=
GitlabCiYamlProcessor
.
new
(
yaml_config
,
path
)
expect
(
config
.
builds
.
first
[
:options
][
:variables
]
).
to
eq
job_variables
expect
(
config
.
job_variables
(
:rspec
)
).
to
eq
job_variables
end
end
end
end
end
end
...
...
This diff is collapsed.
Click to expand it.
spec/models/build_spec.rb
View file @
b7946b50
...
@@ -240,31 +240,27 @@ describe Ci::Build, models: true do
...
@@ -240,31 +240,27 @@ describe Ci::Build, models: true do
end
end
context
'when job variables are defined'
do
context
'when job variables are defined'
do
def
result_variables
job_variables
.
map
do
|
key
,
value
|
{
key:
key
,
value:
value
,
public:
true
}
end
end
before
{
build
.
update_attribute
(
:options
,
variables:
job_variables
)
}
context
'when job variables are unique'
do
context
'when job variables are unique'
do
let
(
:job_variables
)
{
{
KEY1
:
'value1'
,
KEY2
:
'value2
'
}
}
before
{
allow
(
build
).
to
receive
(
:name
)
{
'staging
'
}
}
it
'includes job variables'
do
it
'includes job variables'
do
expect
(
subject
).
to
include
(
*
result_variables
)
expect
(
subject
).
to
include
(
{
key: :KEY1
,
value:
'value1'
,
public:
true
},
{
key: :KEY2
,
value:
'value2'
,
public:
true
}
)
end
end
end
end
context
'when job variable has same key other variable has'
do
context
'when job variable has same key other variable has'
do
let
(
:job_variables
)
{
{
CI_BUILD_NAME
:
'overridde
n'
}
}
before
{
allow
(
build
).
to
receive
(
:name
)
{
'productio
n'
}
}
it
'contains job yaml variable'
do
it
'contains job yaml variable'
do
expect
(
subject
).
to
include
(
*
result_variables
)
expect
(
subject
).
to
include
(
key: :DB_NAME
,
value:
'mysql'
,
public:
true
)
end
end
it
'contains only one variable with this key'
do
it
'contains only one variable with this key'
do
expect
(
subject
.
count
{
|
var
|
var
[
:key
]
==
:
CI_BUILD
_NAME
}
).
to
eq
1
expect
(
subject
.
count
{
|
var
|
var
[
:key
]
==
:
DB
_NAME
}
).
to
eq
1
end
end
end
end
end
end
...
...
This diff is collapsed.
Click to expand it.
spec/support/gitlab_stubs/gitlab_ci.yml
View file @
b7946b50
...
@@ -4,7 +4,7 @@ services:
...
@@ -4,7 +4,7 @@ services:
before_script
:
before_script
:
-
gem install bundler
-
gem install bundler
-
bundle install
-
bundle install
-
bundle exec rake db:create
-
bundle exec rake db:create
variables
:
variables
:
...
@@ -17,7 +17,7 @@ types:
...
@@ -17,7 +17,7 @@ types:
rspec
:
rspec
:
script
:
"
rake
spec"
script
:
"
rake
spec"
tags
:
tags
:
-
ruby
-
ruby
-
postgres
-
postgres
only
:
only
:
...
@@ -26,27 +26,32 @@ rspec:
...
@@ -26,27 +26,32 @@ rspec:
spinach
:
spinach
:
script
:
"
rake
spinach"
script
:
"
rake
spinach"
allow_failure
:
true
allow_failure
:
true
tags
:
tags
:
-
ruby
-
ruby
-
mysql
-
mysql
except
:
except
:
-
tags
-
tags
staging
:
staging
:
variables
:
KEY1
:
value1
KEY2
:
value2
script
:
"
cap
deploy
stating"
script
:
"
cap
deploy
stating"
type
:
deploy
type
:
deploy
tags
:
tags
:
-
ruby
-
ruby
-
mysql
-
mysql
except
:
except
:
-
stable
-
stable
production
:
production
:
variables
:
DB_NAME
:
mysql
type
:
deploy
type
:
deploy
script
:
script
:
-
cap deploy production
-
cap deploy production
-
cap notify
-
cap notify
tags
:
tags
:
-
ruby
-
ruby
-
mysql
-
mysql
only
:
only
:
...
...
This diff is collapsed.
Click to expand it.
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