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
Léo-Paul Géneau
gitlab-ce
Commits
73e17446
Commit
73e17446
authored
Nov 01, 2018
by
Matija Čupić
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move parallelized node index to job options
parent
77715e47
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
23 additions
and
38 deletions
+23
-38
app/models/ci/build.rb
app/models/ci/build.rb
+1
-5
lib/gitlab/ci/config/normalizer.rb
lib/gitlab/ci/config/normalizer.rb
+3
-3
lib/gitlab/ci/yaml_processor.rb
lib/gitlab/ci/yaml_processor.rb
+1
-0
spec/lib/gitlab/ci/config/normalizer_spec.rb
spec/lib/gitlab/ci/config/normalizer_spec.rb
+8
-4
spec/lib/gitlab/ci/yaml_processor_spec.rb
spec/lib/gitlab/ci/yaml_processor_spec.rb
+9
-1
spec/models/ci/build_spec.rb
spec/models/ci/build_spec.rb
+1
-25
No files found.
app/models/ci/build.rb
View file @
73e17446
...
...
@@ -801,16 +801,12 @@ module Ci
variables
.
append
(
key:
"CI_COMMIT_TAG"
,
value:
ref
)
if
tag?
variables
.
append
(
key:
"CI_PIPELINE_TRIGGERED"
,
value:
'true'
)
if
trigger_request
variables
.
append
(
key:
"CI_JOB_MANUAL"
,
value:
'true'
)
if
action?
variables
.
append
(
key:
"CI_NODE_INDEX"
,
value:
node_index
.
to_s
)
if
self
.
options
&
.
include?
(
:parallel
)
variables
.
append
(
key:
"CI_NODE_INDEX"
,
value:
self
.
options
[
:instance
].
to_s
)
if
self
.
options
&
.
include?
(
:instance
)
variables
.
append
(
key:
"CI_NODE_TOTAL"
,
value:
(
self
.
options
&
.
dig
(
:parallel
)
||
1
).
to_s
)
variables
.
concat
(
legacy_variables
)
end
end
def
node_index
name
.
match
(
%r{(
\d
+)/
\d
+$}
).
captures
[
0
]
end
def
gitlab_version_info
@gitlab_version_info
||=
Gitlab
::
VersionInfo
.
parse
(
Gitlab
::
VERSION
)
end
...
...
lib/gitlab/ci/config/normalizer.rb
View file @
73e17446
...
...
@@ -10,8 +10,8 @@ module Gitlab
if
config
[
:parallel
]
total
=
config
[
:parallel
]
names
=
parallelize_job_names
(
name
,
total
)
parallelized_jobs
[
name
]
=
names
Hash
[
names
.
collect
{
|
job_name
|
[
job_name
.
to_sym
,
config
.
merge
(
name:
job_name
)]
}]
parallelized_jobs
[
name
]
=
names
.
map
(
&
:first
)
Hash
[
names
.
collect
{
|
job_name
,
index
|
[
job_name
.
to_sym
,
config
.
merge
(
name:
job_name
,
instance:
index
)]
}]
else
{
name
=>
config
}
end
...
...
@@ -39,7 +39,7 @@ module Gitlab
jobs
=
[]
total
.
times
do
|
idx
|
jobs
<<
"
#{
name
}
#{
idx
+
1
}
/
#{
total
}
"
jobs
<<
[
"
#{
name
}
#{
idx
+
1
}
/
#{
total
}
"
,
idx
+
1
]
end
jobs
...
...
lib/gitlab/ci/yaml_processor.rb
View file @
73e17446
...
...
@@ -51,6 +51,7 @@ module Gitlab
environment:
job
[
:environment
],
retry:
job
[
:retry
],
parallel:
job
[
:parallel
],
instance:
job
[
:instance
],
start_in:
job
[
:start_in
]
}.
compact
}
end
...
...
spec/lib/gitlab/ci/config/normalizer_spec.rb
View file @
73e17446
...
...
@@ -2,7 +2,7 @@ require 'fast_spec_helper'
describe
Gitlab
::
Ci
::
Config
::
Normalizer
do
let
(
:job_name
)
{
:rspec
}
let
(
:job_config
)
{
{
script:
'rspec'
,
parallel:
5
}
}
let
(
:job_config
)
{
{
script:
'rspec'
,
parallel:
5
,
name:
'rspec'
}
}
let
(
:config
)
{
{
job_name
=>
job_config
}
}
describe
'.normalize_jobs'
do
...
...
@@ -13,14 +13,18 @@ describe Gitlab::Ci::Config::Normalizer do
end
it
'has parallelized jobs'
do
job_names
=
described_class
.
send
(
:parallelize_job_names
,
job_name
,
5
).
map
(
&
:to_sym
)
job_names
=
described_class
.
send
(
:parallelize_job_names
,
job_name
,
5
).
map
{
|
job_name
,
index
|
job_name
.
to_sym
}
is_expected
.
to
include
(
*
job_names
)
end
it
'sets job instance in options'
do
expect
(
subject
.
values
).
to
all
(
include
(
:instance
))
end
it
'parallelizes jobs with original config'
do
original_config
=
config
[
job_name
].
except
(
:name
)
configs
=
subject
.
values
.
map
{
|
config
|
config
.
except
(
:name
)
}
configs
=
subject
.
values
.
map
{
|
config
|
config
.
except
(
:name
,
:instance
)
}
expect
(
configs
).
to
all
(
eq
(
original_config
))
end
...
...
@@ -30,7 +34,7 @@ describe Gitlab::Ci::Config::Normalizer do
subject
{
described_class
.
send
(
:parallelize_job_names
,
job_name
,
5
)
}
it
'returns parallelized names'
do
is_expected
.
to
all
(
match
(
%r{
#{
job_name
}
\d
+/
\d
+}
))
expect
(
subject
.
map
(
&
:first
))
.
to
all
(
match
(
%r{
#{
job_name
}
\d
+/
\d
+}
))
end
end
end
spec/lib/gitlab/ci/yaml_processor_spec.rb
View file @
73e17446
...
...
@@ -657,9 +657,17 @@ module Gitlab
it
'returns parallelized jobs'
do
config_processor
=
Gitlab
::
Ci
::
YamlProcessor
.
new
(
config
)
builds
=
config_processor
.
stage_builds_attributes
(
'test'
)
build_options
=
builds
.
map
{
|
build
|
build
[
:options
]
}
expect
(
builds
.
size
).
to
eq
(
5
)
expect
(
builds
.
map
{
|
build
|
build
[
:options
]
}).
to
all
(
include
(
parallel:
parallel
))
expect
(
build_options
).
to
all
(
include
(
:instance
,
parallel:
parallel
))
end
it
'does not have the original job'
do
config_processor
=
Gitlab
::
Ci
::
YamlProcessor
.
new
(
config
)
builds
=
config_processor
.
stage_builds_attributes
(
'test'
)
expect
(
builds
).
not_to
include
(
:rspec
)
end
end
end
...
...
spec/models/ci/build_spec.rb
View file @
73e17446
...
...
@@ -2348,6 +2348,7 @@ describe Ci::Build do
before
do
build
.
options
[
:parallel
]
=
total
build
.
options
[
:instance
]
=
index
build
.
name
=
"
#{
build
.
name
}
#{
index
}
/
#{
total
}
"
end
...
...
@@ -2470,31 +2471,6 @@ describe Ci::Build do
end
end
end
describe
'#node_index'
do
subject
{
build
.
send
(
:node_index
)
}
let
(
:index
)
{
4
}
context
'when build has only one index'
do
before
do
build
.
name
=
"
#{
build
.
name
}
#{
index
}
/5"
end
it
'returns the index'
do
expect
(
subject
).
to
eq
(
index
.
to_s
)
end
end
context
'when build has more than one one index'
do
before
do
build
.
name
=
"test_build 1/3
#{
index
}
/5"
end
it
'returns the last index'
do
expect
(
subject
).
to
eq
(
index
.
to_s
)
end
end
end
end
describe
'#scoped_variables'
do
...
...
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