Skip to content
Snippets Groups Projects
Commit a8f1c5ed authored by Jason Roehm's avatar Jason Roehm
Browse files

add 'triggers' keyword to gitlab-ci.yml 'only' and 'except' fields to allow...

add 'triggers' keyword to gitlab-ci.yml 'only' and 'except' fields to allow control over whether triggers will cause jobs to run
parent ea7d062f
No related branches found
No related tags found
No related merge requests found
module Ci module Ci
class CreateBuildsService class CreateBuildsService
def execute(commit, stage, ref, tag, user, trigger_request, status) def execute(commit, stage, ref, tag, user, trigger_request, status)
builds_attrs = commit.config_processor.builds_for_stage_and_ref(stage, ref, tag) builds_attrs = commit.config_processor.builds_for_stage_and_ref(stage, ref, tag, trigger_request)
   
# check when to create next build # check when to create next build
builds_attrs = builds_attrs.select do |build_attrs| builds_attrs = builds_attrs.select do |build_attrs|
Loading
Loading
Loading
@@ -26,8 +26,8 @@ module Ci
Loading
@@ -26,8 +26,8 @@ module Ci
validate! validate!
end end
   
def builds_for_stage_and_ref(stage, ref, tag = false) def builds_for_stage_and_ref(stage, ref, tag = false, trigger_request = nil)
builds.select{|build| build[:stage] == stage && process?(build[:only], build[:except], ref, tag)} builds.select{|build| build[:stage] == stage && process?(build[:only], build[:except], ref, tag, trigger_request)}
end end
   
def builds def builds
Loading
@@ -266,21 +266,21 @@ module Ci
Loading
@@ -266,21 +266,21 @@ module Ci
value.in?([true, false]) value.in?([true, false])
end end
   
def process?(only_params, except_params, ref, tag) def process?(only_params, except_params, ref, tag, trigger_request)
if only_params.present? if only_params.present?
return false unless matching?(only_params, ref, tag) return false unless matching?(only_params, ref, tag, trigger_request)
end end
   
if except_params.present? if except_params.present?
return false if matching?(except_params, ref, tag) return false if matching?(except_params, ref, tag, trigger_request)
end end
   
true true
end end
   
def matching?(patterns, ref, tag) def matching?(patterns, ref, tag, trigger_request)
patterns.any? do |pattern| patterns.any? do |pattern|
match_ref?(pattern, ref, tag) match_ref?(pattern, ref, tag, trigger_request)
end end
end end
   
Loading
@@ -289,6 +289,7 @@ module Ci
Loading
@@ -289,6 +289,7 @@ module Ci
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 != nil && pattern == 'triggers'
   
if pattern.first == "/" && pattern.last == "/" if pattern.first == "/" && pattern.last == "/"
Regexp.new(pattern[1...-1]) =~ ref Regexp.new(pattern[1...-1]) =~ ref
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment