Commit e1144864 authored by Pedro Pombeiro's avatar Pedro Pombeiro Committed by Nick Thomas

Add tags field to runner in job/pipeline webhooks

- Add tags field to runner instances in data_builder/build.rb
- Add tags field to runner instances in data_builder/pipeline.rb
- Update documentation in webhooks.md
parent ef30b7da
...@@ -10,7 +10,8 @@ class BuildHooksWorker # rubocop:disable Scalability/IdempotentWorker ...@@ -10,7 +10,8 @@ class BuildHooksWorker # rubocop:disable Scalability/IdempotentWorker
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
def perform(build_id) def perform(build_id)
Ci::Build.find_by(id: build_id) Ci::Build.includes({ runner: :tags })
.find_by(id: build_id)
.try(:execute_hooks) .try(:execute_hooks)
end end
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
......
...@@ -10,7 +10,8 @@ class PipelineHooksWorker # rubocop:disable Scalability/IdempotentWorker ...@@ -10,7 +10,8 @@ class PipelineHooksWorker # rubocop:disable Scalability/IdempotentWorker
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
def perform(pipeline_id) def perform(pipeline_id)
Ci::Pipeline.find_by(id: pipeline_id) Ci::Pipeline.includes({ builds: { runner: :tags } })
.find_by(id: pipeline_id)
.try(:execute_hooks) .try(:execute_hooks)
end end
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
......
---
title: Add 'tags' field to runners in job/pipeline webhook payloads
merge_request: 51633
author:
type: changed
...@@ -1151,10 +1151,15 @@ X-Gitlab-Event: Pipeline Hook ...@@ -1151,10 +1151,15 @@ X-Gitlab-Event: Pipeline Hook
"email": "admin@example.com" "email": "admin@example.com"
}, },
"runner": { "runner": {
"id":380987, "id": 380987,
"description":"shared-runners-manager-6.gitlab.com", "description": "shared-runners-manager-6.gitlab.com",
"active":true, "active": true,
"is_shared":true "is_shared": true,
"tags": [
"linux",
"docker",
"shared-runner"
]
}, },
"artifacts_file":{ "artifacts_file":{
"filename": null, "filename": null,
...@@ -1183,7 +1188,11 @@ X-Gitlab-Event: Pipeline Hook ...@@ -1183,7 +1188,11 @@ X-Gitlab-Event: Pipeline Hook
"id":380987, "id":380987,
"description":"shared-runners-manager-6.gitlab.com", "description":"shared-runners-manager-6.gitlab.com",
"active":true, "active":true,
"is_shared":true "is_shared":true,
"tags": [
"linux",
"docker"
]
}, },
"artifacts_file":{ "artifacts_file":{
"filename": null, "filename": null,
...@@ -1209,10 +1218,14 @@ X-Gitlab-Event: Pipeline Hook ...@@ -1209,10 +1218,14 @@ X-Gitlab-Event: Pipeline Hook
"email": "admin@example.com" "email": "admin@example.com"
}, },
"runner": { "runner": {
"id":380987, "id": 380987,
"description":"shared-runners-manager-6.gitlab.com", "description": "shared-runners-manager-6.gitlab.com",
"active":true, "active": true,
"is_shared":true "is_shared": true,
"tags": [
"linux",
"docker"
]
}, },
"artifacts_file":{ "artifacts_file":{
"filename": null, "filename": null,
...@@ -1308,7 +1321,11 @@ X-Gitlab-Event: Job Hook ...@@ -1308,7 +1321,11 @@ X-Gitlab-Event: Job Hook
"active": true, "active": true,
"is_shared": false, "is_shared": false,
"id": 380987, "id": 380987,
"description": "shared-runners-manager-6.gitlab.com" "description": "shared-runners-manager-6.gitlab.com",
"tags": [
"linux",
"docker"
]
} }
} }
``` ```
......
...@@ -82,7 +82,8 @@ module Gitlab ...@@ -82,7 +82,8 @@ module Gitlab
id: runner.id, id: runner.id,
description: runner.description, description: runner.description,
active: runner.active?, active: runner.active?,
is_shared: runner.instance_type? is_shared: runner.instance_type?,
tags: runner.tags&.map(&:name)
} }
end end
end end
......
...@@ -76,7 +76,8 @@ module Gitlab ...@@ -76,7 +76,8 @@ module Gitlab
id: runner.id, id: runner.id,
description: runner.description, description: runner.description,
active: runner.active?, active: runner.active?,
is_shared: runner.instance_type? is_shared: runner.instance_type?,
tags: runner.tags&.map(&:name)
} }
end end
end end
......
...@@ -3,7 +3,8 @@ ...@@ -3,7 +3,8 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe Gitlab::DataBuilder::Build do RSpec.describe Gitlab::DataBuilder::Build do
let(:runner) { create(:ci_runner, :instance) } let!(:tag_names) { %w(tag-1 tag-2) }
let(:runner) { create(:ci_runner, :instance, tag_list: tag_names.map { |n| ActsAsTaggableOn::Tag.create!(name: n)}) }
let(:user) { create(:user) } let(:user) { create(:user) }
let(:build) { create(:ci_build, :running, runner: runner, user: user) } let(:build) { create(:ci_build, :running, runner: runner, user: user) }
...@@ -35,6 +36,7 @@ RSpec.describe Gitlab::DataBuilder::Build do ...@@ -35,6 +36,7 @@ RSpec.describe Gitlab::DataBuilder::Build do
} }
it { expect(data[:commit][:id]).to eq(build.pipeline.id) } it { expect(data[:commit][:id]).to eq(build.pipeline.id) }
it { expect(data[:runner][:id]).to eq(build.runner.id) } it { expect(data[:runner][:id]).to eq(build.runner.id) }
it { expect(data[:runner][:tags]).to match_array(tag_names) }
it { expect(data[:runner][:description]).to eq(build.runner.description) } it { expect(data[:runner][:description]).to eq(build.runner.description) }
context 'commit author_url' do context 'commit author_url' do
......
...@@ -51,13 +51,15 @@ RSpec.describe Gitlab::DataBuilder::Pipeline do ...@@ -51,13 +51,15 @@ RSpec.describe Gitlab::DataBuilder::Pipeline do
context 'build with runner' do context 'build with runner' do
let!(:build) { create(:ci_build, pipeline: pipeline, runner: ci_runner) } let!(:build) { create(:ci_build, pipeline: pipeline, runner: ci_runner) }
let(:ci_runner) { create(:ci_runner) } let!(:tag_names) { %w(tag-1 tag-2) }
let(:ci_runner) { create(:ci_runner, tag_list: tag_names.map { |n| ActsAsTaggableOn::Tag.create!(name: n)}) }
it 'has runner attributes', :aggregate_failures do it 'has runner attributes', :aggregate_failures do
expect(runner_data[:id]).to eq(ci_runner.id) expect(runner_data[:id]).to eq(ci_runner.id)
expect(runner_data[:description]).to eq(ci_runner.description) expect(runner_data[:description]).to eq(ci_runner.description)
expect(runner_data[:active]).to eq(ci_runner.active) expect(runner_data[:active]).to eq(ci_runner.active)
expect(runner_data[:is_shared]).to eq(ci_runner.instance_type?) expect(runner_data[:is_shared]).to eq(ci_runner.instance_type?)
expect(runner_data[:tags]).to match_array(tag_names)
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment