diff --git a/app/services/ci/create_builds_service.rb b/app/services/ci/create_builds_service.rb index 002f7ba12785aca3a496af1a3c9e8a4f90455526..2cd51a7610f6310e5c0c098244e74e2ddba27e0a 100644 --- a/app/services/ci/create_builds_service.rb +++ b/app/services/ci/create_builds_service.rb @@ -1,7 +1,7 @@ module Ci class CreateBuildsService 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 builds_attrs = builds_attrs.select do |build_attrs| diff --git a/lib/ci/gitlab_ci_yaml_processor.rb b/lib/ci/gitlab_ci_yaml_processor.rb index c89e1b5101933cbd11cabb3f186c4226221fcdd0..bc6fea9a286aa1fb9fdbca2ed7195f5be3b211cf 100644 --- a/lib/ci/gitlab_ci_yaml_processor.rb +++ b/lib/ci/gitlab_ci_yaml_processor.rb @@ -26,8 +26,8 @@ module Ci validate! end - def builds_for_stage_and_ref(stage, ref, tag = false) - builds.select{|build| build[:stage] == stage && process?(build[:only], build[:except], ref, tag)} + 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, trigger_request)} end def builds @@ -266,21 +266,21 @@ module Ci value.in?([true, false]) end - def process?(only_params, except_params, ref, tag) + def process?(only_params, except_params, ref, tag, trigger_request) if only_params.present? - return false unless matching?(only_params, ref, tag) + return false unless matching?(only_params, ref, tag, trigger_request) end if except_params.present? - return false if matching?(except_params, ref, tag) + return false if matching?(except_params, ref, tag, trigger_request) end true end - def matching?(patterns, ref, tag) + def matching?(patterns, ref, tag, trigger_request) patterns.any? do |pattern| - match_ref?(pattern, ref, tag) + match_ref?(pattern, ref, tag, trigger_request) end end @@ -289,6 +289,7 @@ module Ci return false if path && path != self.path return true if tag && pattern == 'tags' return true if !tag && pattern == 'branches' + return true if trigger_request != nil && pattern == 'triggers' if pattern.first == "/" && pattern.last == "/" Regexp.new(pattern[1...-1]) =~ ref