summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFilip Krakowski <Filip.Krakowski@Uni-Duesseldorf.de>2017-06-01 21:55:57 +0200
committerShinya Maeda <gitlab.shinyamaeda@gmail.com>2017-06-08 00:34:58 +0900
commit8db63b26284d949000316a38676ef6fad970f657 (patch)
tree788935b6fe1b868b3d78f3a0d57ef6adb1490fae
parentfe9b78d673965db2adb954725317fe1a1b76728d (diff)
downloadgitlab-ce-8db63b26284d949000316a38676ef6fad970f657.tar.gz
Use pipeline.source to determine what triggered a pipeline
-rw-r--r--doc/ci/yaml/README.md2
-rw-r--r--lib/ci/gitlab_ci_yaml_processor.rb32
-rw-r--r--spec/lib/ci/gitlab_ci_yaml_processor_spec.rb8
3 files changed, 21 insertions, 21 deletions
diff --git a/doc/ci/yaml/README.md b/doc/ci/yaml/README.md
index 7c085bf77c9..52ded37c2a7 100644
--- a/doc/ci/yaml/README.md
+++ b/doc/ci/yaml/README.md
@@ -411,7 +411,7 @@ job:
```
In this example, `job` will run only for refs that are tagged, or if a build is
-explicitly requested via an API trigger or a Pipeline Schedule.
+explicitly requested via an API trigger or a [Pipeline Schedule](../../user/project/pipelines/schedules.md).
```yaml
job:
diff --git a/lib/ci/gitlab_ci_yaml_processor.rb b/lib/ci/gitlab_ci_yaml_processor.rb
index b941a54c85a..98600a48d0f 100644
--- a/lib/ci/gitlab_ci_yaml_processor.rb
+++ b/lib/ci/gitlab_ci_yaml_processor.rb
@@ -20,26 +20,26 @@ module Ci
raise ValidationError, e.message
end
- def jobs_for_ref(ref, tag = false, trigger_request = nil, pipeline_schedule = nil)
+ def jobs_for_ref(ref, tag = false, source = nil)
@jobs.select do |_, job|
- process?(job[:only], job[:except], ref, tag, trigger_request, pipeline_schedule)
+ process?(job[:only], job[:except], ref, tag, source)
end
end
- def jobs_for_stage_and_ref(stage, ref, tag = false, trigger_request = nil, pipeline_schedule = nil)
- jobs_for_ref(ref, tag, trigger_request, pipeline_schedule).select do |_, job|
+ def jobs_for_stage_and_ref(stage, ref, tag = false, source = nil)
+ jobs_for_ref(ref, tag, source).select do |_, job|
job[:stage] == stage
end
end
- def builds_for_ref(ref, tag = false, trigger_request = nil, pipeline_schedule = nil)
- jobs_for_ref(ref, tag, trigger_request, pipeline_schedule).map do |name, _|
+ def builds_for_ref(ref, tag = false, source = nil)
+ jobs_for_ref(ref, tag, source).map do |name, _|
build_attributes(name)
end
end
- 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, pipeline_schedule).map do |name, _|
+ def builds_for_stage_and_ref(stage, ref, tag = false, source = nil)
+ jobs_for_stage_and_ref(stage, ref, tag, source).map do |name, _|
build_attributes(name)
end
end
@@ -193,31 +193,31 @@ module Ci
end
end
- def process?(only_params, except_params, ref, tag, trigger_request, pipeline_schedule)
+ def process?(only_params, except_params, ref, tag, source)
if only_params.present?
- return false unless matching?(only_params, ref, tag, trigger_request, pipeline_schedule)
+ return false unless matching?(only_params, ref, tag, source)
end
if except_params.present?
- return false if matching?(except_params, ref, tag, trigger_request, pipeline_schedule)
+ return false if matching?(except_params, ref, tag, source)
end
true
end
- def matching?(patterns, ref, tag, trigger_request, pipeline_schedule)
+ def matching?(patterns, ref, tag, source)
patterns.any? do |pattern|
- match_ref?(pattern, ref, tag, trigger_request, pipeline_schedule)
+ match_ref?(pattern, ref, tag, source)
end
end
- def match_ref?(pattern, ref, tag, trigger_request, pipeline_schedule)
+ def match_ref?(pattern, ref, tag, source)
pattern, path = pattern.split('@', 2)
return false if path && path != self.path
return true if tag && pattern == 'tags'
return true if !tag && pattern == 'branches'
- return true if trigger_request.present? && pattern == 'triggers'
- return true if pipeline_schedule.present? && pattern == 'schedules'
+ return true if source == 'trigger' && pattern == 'triggers'
+ return true if source == 'schedule' && pattern == 'schedules'
if pattern.first == "/" && pattern.last == "/"
Regexp.new(pattern[1...-1]) =~ ref
diff --git a/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb b/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
index 83085f61b37..aa281301faf 100644
--- a/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
+++ b/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
@@ -227,7 +227,7 @@ module Ci
config_processor = GitlabCiYamlProcessor.new(config, path)
- 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, 'trigger').size).to eq(1)
end
it "returns builds if only has a schedules keyword specified and a schedule is provided" do
@@ -238,7 +238,7 @@ module Ci
config_processor = GitlabCiYamlProcessor.new(config, path)
- expect(config_processor.builds_for_stage_and_ref(type, "deploy", false, false, true).size).to eq(1)
+ expect(config_processor.builds_for_stage_and_ref(type, "deploy", false, 'schedule').size).to eq(1)
end
it "does not return builds if only has a triggers keyword specified and no trigger is provided" do
@@ -405,7 +405,7 @@ module Ci
config_processor = GitlabCiYamlProcessor.new(config, path)
- 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, 'trigger').size).to eq(0)
end
it "does not return builds if except has a schedules keyword specified and a schedule is provided" do
@@ -416,7 +416,7 @@ module Ci
config_processor = GitlabCiYamlProcessor.new(config, path)
- expect(config_processor.builds_for_stage_and_ref(type, "deploy", false, false, true).size).to eq(0)
+ expect(config_processor.builds_for_stage_and_ref(type, "deploy", false, 'schedule').size).to eq(0)
end
it "returns builds if except has a triggers keyword specified and no trigger is provided" do