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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
6c8e72b4
Commit
6c8e72b4
authored
Jun 01, 2017
by
Filip Krakowski
Committed by
Shinya Maeda
Jun 08, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add 'schedules' keyword to 'only' and 'except'
parent
0601ac5d
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
62 additions
and
16 deletions
+62
-16
doc/ci/yaml/README.md
doc/ci/yaml/README.md
+3
-2
lib/ci/gitlab_ci_yaml_processor.rb
lib/ci/gitlab_ci_yaml_processor.rb
+15
-14
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
+44
-0
No files found.
doc/ci/yaml/README.md
View file @
6c8e72b4
...
@@ -393,7 +393,7 @@ There are a few rules that apply to the usage of refs policy:
...
@@ -393,7 +393,7 @@ There are a few rules that apply to the usage of refs policy:
*
`only`
and
`except`
are inclusive. If both
`only`
and
`except`
are defined
*
`only`
and
`except`
are inclusive. If both
`only`
and
`except`
are defined
in a job specification, the ref is filtered by
`only`
and
`except`
.
in a job specification, the ref is filtered by
`only`
and
`except`
.
*
`only`
and
`except`
allow the use of regular expressions.
*
`only`
and
`except`
allow the use of regular expressions.
*
`only`
and
`except`
allow the use of special keywords:
`branches`
,
`tags`
,
and
`trigger
s`
.
*
`only`
and
`except`
allow the use of special keywords:
`branches`
,
`tags`
,
`triggers`
and
`schedule
s`
.
*
`only`
and
`except`
allow to specify a repository path to filter jobs for
*
`only`
and
`except`
allow to specify a repository path to filter jobs for
forks.
forks.
...
@@ -411,7 +411,7 @@ job:
...
@@ -411,7 +411,7 @@ job:
```
```
In this example,
`job`
will run only for refs that are tagged, or if a build is
In this example,
`job`
will run only for refs that are tagged, or if a build is
explicitly requested via an API trigger.
explicitly requested via an API trigger
or a Pipeline Schedule
.
```
yaml
```
yaml
job
:
job
:
...
@@ -419,6 +419,7 @@ job:
...
@@ -419,6 +419,7 @@ job:
only
:
only
:
-
tags
-
tags
-
triggers
-
triggers
-
schedules
```
```
The repository path can be used to have jobs executed only for the parent
The repository path can be used to have jobs executed only for the parent
...
...
lib/ci/gitlab_ci_yaml_processor.rb
View file @
6c8e72b4
...
@@ -20,26 +20,26 @@ module Ci
...
@@ -20,26 +20,26 @@ module Ci
raise
ValidationError
,
e
.
message
raise
ValidationError
,
e
.
message
end
end
def
jobs_for_ref
(
ref
,
tag
=
false
,
trigger_request
=
nil
)
def
jobs_for_ref
(
ref
,
tag
=
false
,
trigger_request
=
nil
,
pipeline_schedule
=
nil
)
@jobs
.
select
do
|
_
,
job
|
@jobs
.
select
do
|
_
,
job
|
process?
(
job
[
:only
],
job
[
:except
],
ref
,
tag
,
trigger_request
)
process?
(
job
[
:only
],
job
[
:except
],
ref
,
tag
,
trigger_request
,
pipeline_schedule
)
end
end
end
end
def
jobs_for_stage_and_ref
(
stage
,
ref
,
tag
=
false
,
trigger_request
=
nil
)
def
jobs_for_stage_and_ref
(
stage
,
ref
,
tag
=
false
,
trigger_request
=
nil
,
pipeline_schedule
=
nil
)
jobs_for_ref
(
ref
,
tag
,
trigger_request
).
select
do
|
_
,
job
|
jobs_for_ref
(
ref
,
tag
,
trigger_request
,
pipeline_schedule
).
select
do
|
_
,
job
|
job
[
:stage
]
==
stage
job
[
:stage
]
==
stage
end
end
end
end
def
builds_for_ref
(
ref
,
tag
=
false
,
trigger_request
=
nil
)
def
builds_for_ref
(
ref
,
tag
=
false
,
trigger_request
=
nil
,
pipeline_schedule
=
nil
)
jobs_for_ref
(
ref
,
tag
,
trigger_request
).
map
do
|
name
,
_
|
jobs_for_ref
(
ref
,
tag
,
trigger_request
,
pipeline_schedule
).
map
do
|
name
,
_
|
build_attributes
(
name
)
build_attributes
(
name
)
end
end
end
end
def
builds_for_stage_and_ref
(
stage
,
ref
,
tag
=
false
,
trigger_request
=
nil
)
def
builds_for_stage_and_ref
(
stage
,
ref
,
tag
=
false
,
trigger_request
=
nil
,
pipeline_schedule
=
nil
)
jobs_for_stage_and_ref
(
stage
,
ref
,
tag
,
trigger_request
).
map
do
|
name
,
_
|
jobs_for_stage_and_ref
(
stage
,
ref
,
tag
,
trigger_request
,
pipeline_schedule
).
map
do
|
name
,
_
|
build_attributes
(
name
)
build_attributes
(
name
)
end
end
end
end
...
@@ -193,30 +193,31 @@ module Ci
...
@@ -193,30 +193,31 @@ module Ci
end
end
end
end
def
process?
(
only_params
,
except_params
,
ref
,
tag
,
trigger_request
)
def
process?
(
only_params
,
except_params
,
ref
,
tag
,
trigger_request
,
pipeline_schedule
)
if
only_params
.
present?
if
only_params
.
present?
return
false
unless
matching?
(
only_params
,
ref
,
tag
,
trigger_request
)
return
false
unless
matching?
(
only_params
,
ref
,
tag
,
trigger_request
,
pipeline_schedule
)
end
end
if
except_params
.
present?
if
except_params
.
present?
return
false
if
matching?
(
except_params
,
ref
,
tag
,
trigger_request
)
return
false
if
matching?
(
except_params
,
ref
,
tag
,
trigger_request
,
pipeline_schedule
)
end
end
true
true
end
end
def
matching?
(
patterns
,
ref
,
tag
,
trigger_request
)
def
matching?
(
patterns
,
ref
,
tag
,
trigger_request
,
pipeline_schedule
)
patterns
.
any?
do
|
pattern
|
patterns
.
any?
do
|
pattern
|
match_ref?
(
pattern
,
ref
,
tag
,
trigger_request
)
match_ref?
(
pattern
,
ref
,
tag
,
trigger_request
,
pipeline_schedule
)
end
end
end
end
def
match_ref?
(
pattern
,
ref
,
tag
,
trigger_request
)
def
match_ref?
(
pattern
,
ref
,
tag
,
trigger_request
,
pipeline_schedule
)
pattern
,
path
=
pattern
.
split
(
'@'
,
2
)
pattern
,
path
=
pattern
.
split
(
'@'
,
2
)
return
false
if
path
&&
path
!=
self
.
path
return
false
if
path
&&
path
!=
self
.
path
return
true
if
tag
&&
pattern
==
'tags'
return
true
if
tag
&&
pattern
==
'tags'
return
true
if
!
tag
&&
pattern
==
'branches'
return
true
if
!
tag
&&
pattern
==
'branches'
return
true
if
trigger_request
.
present?
&&
pattern
==
'triggers'
return
true
if
trigger_request
.
present?
&&
pattern
==
'triggers'
return
true
if
pipeline_schedule
.
present?
&&
pattern
==
'schedules'
if
pattern
.
first
==
"/"
&&
pattern
.
last
==
"/"
if
pattern
.
first
==
"/"
&&
pattern
.
last
==
"/"
Regexp
.
new
(
pattern
[
1
...-
1
])
=~
ref
Regexp
.
new
(
pattern
[
1
...-
1
])
=~
ref
...
...
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
View file @
6c8e72b4
...
@@ -230,6 +230,17 @@ module Ci
...
@@ -230,6 +230,17 @@ module Ci
expect
(
config_processor
.
builds_for_stage_and_ref
(
type
,
"deploy"
,
false
,
true
).
size
).
to
eq
(
1
)
expect
(
config_processor
.
builds_for_stage_and_ref
(
type
,
"deploy"
,
false
,
true
).
size
).
to
eq
(
1
)
end
end
it
"returns builds if only has a schedules keyword specified and a schedule is provided"
do
config
=
YAML
.
dump
({
before_script:
[
"pwd"
],
rspec:
{
script:
"rspec"
,
type:
type
,
only:
[
"schedules"
]
}
})
config_processor
=
GitlabCiYamlProcessor
.
new
(
config
,
path
)
expect
(
config_processor
.
builds_for_stage_and_ref
(
type
,
"deploy"
,
false
,
false
,
true
).
size
).
to
eq
(
1
)
end
it
"does not return builds if only has a triggers keyword specified and no trigger is provided"
do
it
"does not return builds if only has a triggers keyword specified and no trigger is provided"
do
config
=
YAML
.
dump
({
config
=
YAML
.
dump
({
before_script:
[
"pwd"
],
before_script:
[
"pwd"
],
...
@@ -241,6 +252,17 @@ module Ci
...
@@ -241,6 +252,17 @@ module Ci
expect
(
config_processor
.
builds_for_stage_and_ref
(
type
,
"deploy"
).
size
).
to
eq
(
0
)
expect
(
config_processor
.
builds_for_stage_and_ref
(
type
,
"deploy"
).
size
).
to
eq
(
0
)
end
end
it
"does not return builds if only has a schedules keyword specified and no schedule is provided"
do
config
=
YAML
.
dump
({
before_script:
[
"pwd"
],
rspec:
{
script:
"rspec"
,
type:
type
,
only:
[
"schedules"
]
}
})
config_processor
=
GitlabCiYamlProcessor
.
new
(
config
,
path
)
expect
(
config_processor
.
builds_for_stage_and_ref
(
type
,
"deploy"
).
size
).
to
eq
(
0
)
end
it
"returns builds if only has current repository path"
do
it
"returns builds if only has current repository path"
do
config
=
YAML
.
dump
({
config
=
YAML
.
dump
({
before_script:
[
"pwd"
],
before_script:
[
"pwd"
],
...
@@ -386,6 +408,17 @@ module Ci
...
@@ -386,6 +408,17 @@ module Ci
expect
(
config_processor
.
builds_for_stage_and_ref
(
type
,
"deploy"
,
false
,
true
).
size
).
to
eq
(
0
)
expect
(
config_processor
.
builds_for_stage_and_ref
(
type
,
"deploy"
,
false
,
true
).
size
).
to
eq
(
0
)
end
end
it
"does not return builds if except has a schedules keyword specified and a schedule is provided"
do
config
=
YAML
.
dump
({
before_script:
[
"pwd"
],
rspec:
{
script:
"rspec"
,
type:
type
,
except:
[
"schedules"
]
}
})
config_processor
=
GitlabCiYamlProcessor
.
new
(
config
,
path
)
expect
(
config_processor
.
builds_for_stage_and_ref
(
type
,
"deploy"
,
false
,
false
,
true
).
size
).
to
eq
(
0
)
end
it
"returns builds if except has a triggers keyword specified and no trigger is provided"
do
it
"returns builds if except has a triggers keyword specified and no trigger is provided"
do
config
=
YAML
.
dump
({
config
=
YAML
.
dump
({
before_script:
[
"pwd"
],
before_script:
[
"pwd"
],
...
@@ -397,6 +430,17 @@ module Ci
...
@@ -397,6 +430,17 @@ module Ci
expect
(
config_processor
.
builds_for_stage_and_ref
(
type
,
"deploy"
).
size
).
to
eq
(
1
)
expect
(
config_processor
.
builds_for_stage_and_ref
(
type
,
"deploy"
).
size
).
to
eq
(
1
)
end
end
it
"returns builds if except has a schedules keyword specified and no schedule is provided"
do
config
=
YAML
.
dump
({
before_script:
[
"pwd"
],
rspec:
{
script:
"rspec"
,
type:
type
,
except:
[
"schedules"
]
}
})
config_processor
=
GitlabCiYamlProcessor
.
new
(
config
,
path
)
expect
(
config_processor
.
builds_for_stage_and_ref
(
type
,
"deploy"
).
size
).
to
eq
(
1
)
end
it
"does not return builds if except has current repository path"
do
it
"does not return builds if except has current repository path"
do
config
=
YAML
.
dump
({
config
=
YAML
.
dump
({
before_script:
[
"pwd"
],
before_script:
[
"pwd"
],
...
...
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