summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2016-05-05 13:08:17 +0200
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2016-05-19 22:01:53 +0200
commit83df6384558c27d3ff7282e6d66b06fa7e9c0c60 (patch)
tree57d1ad3cc992e99a24e4144045c8c6d091ab0661
parent2aa57071947e562f302b3858a249339024ef7119 (diff)
downloadgitlab-ce-83df6384558c27d3ff7282e6d66b06fa7e9c0c60.tar.gz
Disallow runner to pick untagged build if configured
-rw-r--r--app/models/ci/build.rb4
-rw-r--r--spec/models/build_spec.rb38
2 files changed, 31 insertions, 11 deletions
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb
index 92327bdb08d..77a2dec4f72 100644
--- a/app/models/ci/build.rb
+++ b/app/models/ci/build.rb
@@ -290,6 +290,10 @@ module Ci
end
def can_be_served?(runner)
+ if tag_list.empty? && !runner.run_untagged?
+ return false
+ end
+
(tag_list - runner.tag_list).empty?
end
diff --git a/spec/models/build_spec.rb b/spec/models/build_spec.rb
index b5d356aa066..5da54e07de8 100644
--- a/spec/models/build_spec.rb
+++ b/spec/models/build_spec.rb
@@ -259,11 +259,11 @@ describe Ci::Build, models: true do
end
describe '#can_be_served?' do
- let(:runner) { FactoryGirl.create :ci_runner }
+ let(:runner) { create(:ci_runner) }
before { build.project.runners << runner }
- context 'runner without tags' do
+ context 'when runner does not have tags' do
it 'can handle builds without tags' do
expect(build.can_be_served?(runner)).to be_truthy
end
@@ -274,21 +274,37 @@ describe Ci::Build, models: true do
end
end
- context 'runner with tags' do
+ context 'when runner has tags' do
before { runner.tag_list = ['bb', 'cc'] }
- it 'can handle builds without tags' do
- expect(build.can_be_served?(runner)).to be_truthy
+ shared_examples 'tagged build picker' do
+ it 'can handle build with matching tags' do
+ build.tag_list = ['bb']
+ expect(build.can_be_served?(runner)).to be_truthy
+ end
+
+ it 'cannot handle build without matching tags' do
+ build.tag_list = ['aa']
+ expect(build.can_be_served?(runner)).to be_falsey
+ end
end
- it 'can handle build with matching tags' do
- build.tag_list = ['bb']
- expect(build.can_be_served?(runner)).to be_truthy
+ context 'when runner can pick untagged jobs' do
+ it 'can handle builds without tags' do
+ expect(build.can_be_served?(runner)).to be_truthy
+ end
+
+ it_behaves_like 'tagged build picker'
end
- it 'cannot handle build with not matching tags' do
- build.tag_list = ['aa']
- expect(build.can_be_served?(runner)).to be_falsey
+ context 'when runner can not pick untagged jobs' do
+ before { runner.run_untagged = false }
+
+ it 'can not handle builds without tags' do
+ expect(build.can_be_served?(runner)).to be_falsey
+ end
+
+ it_behaves_like 'tagged build picker'
end
end
end