summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/ci/api/runners.rb15
-rw-r--r--spec/requests/ci/api/runners_spec.rb35
2 files changed, 38 insertions, 12 deletions
diff --git a/lib/ci/api/runners.rb b/lib/ci/api/runners.rb
index 192b1d18a51..ea35d0f6dd0 100644
--- a/lib/ci/api/runners.rb
+++ b/lib/ci/api/runners.rb
@@ -28,20 +28,17 @@ module Ci
post "register" do
required_attributes! [:token]
+ attributes = { description: params[:description],
+ tag_list: params[:tag_list],
+ run_untagged: params[:run_untagged] || true }
+
runner =
if runner_registration_token_valid?
# Create shared runner. Requires admin access
- Ci::Runner.create(
- description: params[:description],
- tag_list: params[:tag_list],
- is_shared: true
- )
+ Ci::Runner.create(attributes.merge(is_shared: true))
elsif project = Project.find_by(runners_token: params[:token])
# Create a specific runner for project.
- project.runners.create(
- description: params[:description],
- tag_list: params[:tag_list]
- )
+ project.runners.create(attributes)
end
return forbidden! unless runner
diff --git a/spec/requests/ci/api/runners_spec.rb b/spec/requests/ci/api/runners_spec.rb
index 5d6f5f774ea..eb11258cbbb 100644
--- a/spec/requests/ci/api/runners_spec.rb
+++ b/spec/requests/ci/api/runners_spec.rb
@@ -15,13 +15,17 @@ describe Ci::API::API do
context 'when runner token is provided' do
before { post ci_api("/runners/register"), token: registration_token }
- it 'creates runner' do
+ it 'creates runner with default values' do
expect(response.status).to eq(201)
+ expect(Ci::Runner.first.run_untagged).to be true
end
end
context 'when runner description is provided' do
- before { post ci_api("/runners/register"), token: registration_token, description: "server.hostname" }
+ before do
+ post ci_api("/runners/register"), token: registration_token,
+ description: "server.hostname"
+ end
it 'creates runner' do
expect(response.status).to eq(201)
@@ -30,7 +34,10 @@ describe Ci::API::API do
end
context 'when runner tags are provided' do
- before { post ci_api("/runners/register"), token: registration_token, tag_list: "tag1, tag2" }
+ before do
+ post ci_api("/runners/register"), token: registration_token,
+ tag_list: "tag1, tag2"
+ end
it 'creates runner' do
expect(response.status).to eq(201)
@@ -38,6 +45,28 @@ describe Ci::API::API do
end
end
+ context 'when option for running untagged jobs is provided' do
+ context 'when tags are provided' do
+ it 'creates runner' do
+ post ci_api("/runners/register"), token: registration_token,
+ run_untagged: false,
+ tag_list: ['tag']
+
+ expect(response.status).to eq(201)
+ expect(Ci::Runner.first.run_untagged).to be false
+ end
+ end
+
+ context 'when tags are not provided' do
+ it 'does not create runner' do
+ post ci_api("/runners/register"), token: registration_token,
+ run_untagged: false
+
+ expect(response.status).to eq(404)
+ end
+ end
+ end
+
context 'when project token is provided' do
let(:project) { FactoryGirl.create(:empty_project) }
before { post ci_api("/runners/register"), token: project.runners_token }