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
8dd27b47
Commit
8dd27b47
authored
Apr 21, 2016
by
Tomasz Maczukin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add posibility to define a hidden job without 'script' in .gitlab-ci.yml
parent
80893cad
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
117 additions
and
53 deletions
+117
-53
lib/ci/gitlab_ci_yaml_processor.rb
lib/ci/gitlab_ci_yaml_processor.rb
+7
-4
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
+110
-49
No files found.
lib/ci/gitlab_ci_yaml_processor.rb
View file @
8dd27b47
...
@@ -63,9 +63,8 @@ module Ci
...
@@ -63,9 +63,8 @@ module Ci
@cache
=
@config
[
:cache
]
@cache
=
@config
[
:cache
]
@config
.
except!
(
*
ALLOWED_YAML_KEYS
)
@config
.
except!
(
*
ALLOWED_YAML_KEYS
)
# anything that doesn't have script is considered as unknown
@config
.
each
do
|
name
,
param
|
@config
.
each
do
|
name
,
param
|
raise
ValidationError
,
"Unknown parameter:
#{
name
}
"
unless
param
.
is_a?
(
Hash
)
&&
param
.
has_key?
(
:script
)
raise
ValidationError
,
"Unknown parameter:
#{
name
}
"
unless
is_a_job?
(
name
,
param
)
end
end
unless
@config
.
values
.
any?
{
|
job
|
job
.
is_a?
(
Hash
)}
unless
@config
.
values
.
any?
{
|
job
|
job
.
is_a?
(
Hash
)}
...
@@ -80,6 +79,12 @@ module Ci
...
@@ -80,6 +79,12 @@ module Ci
end
end
end
end
def
is_a_job?
(
name
,
value
)
return
true
if
value
.
is_a?
(
Hash
)
&&
value
.
has_key?
(
:script
)
return
true
if
name
.
to_s
.
start_with?
(
'.'
)
false
end
def
build_job
(
name
,
job
)
def
build_job
(
name
,
job
)
{
{
stage_idx:
stages
.
index
(
job
[
:stage
]),
stage_idx:
stages
.
index
(
job
[
:stage
]),
...
@@ -112,8 +117,6 @@ module Ci
...
@@ -112,8 +117,6 @@ module Ci
true
true
end
end
private
def
validate_global!
def
validate_global!
unless
validate_array_of_strings
(
@before_script
)
unless
validate_array_of_strings
(
@before_script
)
raise
ValidationError
,
"before_script should be an array of strings"
raise
ValidationError
,
"before_script should be an array of strings"
...
...
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
View file @
8dd27b47
...
@@ -648,70 +648,131 @@ module Ci
...
@@ -648,70 +648,131 @@ module Ci
end
end
describe
"Hidden jobs"
do
describe
"Hidden jobs"
do
let
(
:config
)
do
let
(
:config_processor
)
{
GitlabCiYamlProcessor
.
new
(
config
)
}
YAML
.
dump
({
subject
{
config_processor
.
builds_for_stage_and_ref
(
"test"
,
"master"
)
}
'.hidden_job'
=>
{
script:
'test'
},
'normal_job'
=>
{
script:
'test'
}
shared_examples
'hidden_job_handling'
do
})
it
"doesn't create jobs that starts with dot"
do
expect
(
subject
.
size
).
to
eq
(
1
)
expect
(
subject
.
first
).
to
eq
({
except:
nil
,
stage:
"test"
,
stage_idx:
1
,
name: :normal_job
,
only:
nil
,
commands:
"test"
,
tag_list:
[],
options:
{},
when:
"on_success"
,
allow_failure:
false
})
end
end
end
let
(
:config_processor
)
{
GitlabCiYamlProcessor
.
new
(
config
)
}
context
'When hidden job have a script definition'
do
let
(
:config
)
do
YAML
.
dump
({
'.hidden_job'
=>
{
image:
'ruby:2.1'
,
script:
'test'
},
'normal_job'
=>
{
script:
'test'
}
})
end
subject
{
config_processor
.
builds_for_stage_and_ref
(
"test"
,
"master"
)
}
it_behaves_like
'hidden_job_handling'
end
it
"doesn't create jobs that starts with dot"
do
context
"When hidden job doesn't have a script definition"
do
expect
(
subject
.
size
).
to
eq
(
1
)
let
(
:config
)
do
expect
(
subject
.
first
).
to
eq
({
YAML
.
dump
({
except:
nil
,
'.hidden_job'
=>
{
image:
'ruby:2.1'
},
stage:
"test"
,
'normal_job'
=>
{
script:
'test'
}
stage_idx:
1
,
})
name: :normal_job
,
end
only:
nil
,
commands:
"test"
,
it_behaves_like
'hidden_job_handling'
tag_list:
[],
options:
{},
when:
"on_success"
,
allow_failure:
false
})
end
end
end
end
describe
"YAML Alias/Anchor"
do
describe
"YAML Alias/Anchor"
do
it
"is correctly supported for jobs"
do
let
(
:config_processor
)
{
GitlabCiYamlProcessor
.
new
(
config
)
}
config
=
<<
EOT
subject
{
config_processor
.
builds_for_stage_and_ref
(
"build"
,
"master"
)
}
shared_examples
'job_templates_handling'
do
it
"is correctly supported for jobs"
do
expect
(
subject
.
size
).
to
eq
(
2
)
expect
(
subject
.
first
).
to
eq
({
except:
nil
,
stage:
"build"
,
stage_idx:
0
,
name: :job1
,
only:
nil
,
commands:
"execute-script-for-job"
,
tag_list:
[],
options:
{},
when:
"on_success"
,
allow_failure:
false
})
expect
(
subject
.
second
).
to
eq
({
except:
nil
,
stage:
"build"
,
stage_idx:
0
,
name: :job2
,
only:
nil
,
commands:
"execute-script-for-job"
,
tag_list:
[],
options:
{},
when:
"on_success"
,
allow_failure:
false
})
end
end
context
'When template is a job'
do
let
(
:config
)
do
<<
EOT
job1: &JOBTMPL
job1: &JOBTMPL
stage: build
script: execute-script-for-job
script: execute-script-for-job
job2: *JOBTMPL
job2: *JOBTMPL
EOT
EOT
end
config_processor
=
GitlabCiYamlProcessor
.
new
(
config
)
it_behaves_like
'job_templates_handling'
end
expect
(
config_processor
.
builds_for_stage_and_ref
(
"test"
,
"master"
).
size
).
to
eq
(
2
)
context
'When template is a hidden job'
do
expect
(
config_processor
.
builds_for_stage_and_ref
(
"test"
,
"master"
).
first
).
to
eq
({
let
(
:config
)
do
except:
nil
,
<<
EOT
stage:
"test"
,
.template: &JOBTMPL
stage_idx:
1
,
stage: build
name: :job1
,
script: execute-script-for-job
only:
nil
,
commands:
"execute-script-for-job"
,
job1: *JOBTMPL
tag_list:
[],
options:
{},
job2: *JOBTMPL
when:
"on_success"
,
EOT
allow_failure:
false
end
})
expect
(
config_processor
.
builds_for_stage_and_ref
(
"test"
,
"master"
).
second
).
to
eq
({
it_behaves_like
'job_templates_handling'
except:
nil
,
end
stage:
"test"
,
stage_idx:
1
,
context
"When job adds it's own keys to a template definition"
do
name: :job2
,
let
(
:config
)
do
only:
nil
,
<<
EOT
commands:
"execute-script-for-job"
,
.template: &JOBTMPL
tag_list:
[],
stage: build
options:
{},
when:
"on_success"
,
job1:
allow_failure:
false
<<: *JOBTMPL
})
script: execute-script-for-job
job2:
<<: *JOBTMPL
script: execute-script-for-job
EOT
end
it_behaves_like
'job_templates_handling'
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