Commit aba438aa authored by Gaetan Semet's avatar Gaetan Semet Committed by Thong Kuah

Add runner info in build event

parent dc0f1c69
---
title: Add runner information in build web hook event
merge_request: 20709
author: Gaetan Semet
type: added
......@@ -1223,6 +1223,7 @@ X-Gitlab-Event: Job Hook
"build_duration": null,
"build_allow_failure": false,
"build_failure_reason": "script_failure",
"pipeline_id": 2366,
"project_id": 380,
"project_name": "gitlab-org/gitlab-test",
"user": {
......@@ -1248,10 +1249,18 @@ X-Gitlab-Event: Job Hook
"git_ssh_url": "git@192.168.64.1:gitlab-org/gitlab-test.git",
"git_http_url": "http://192.168.64.1:3005/gitlab-org/gitlab-test.git",
"visibility_level": 20
},
"runner": {
"active": true,
"is_shared": false,
"id": 380987,
"description": "shared-runners-manager-6.gitlab.com"
}
}
```
Note that `commit.id` is the id of the pipeline, not the id of the commit.
## Image URL rewriting
From GitLab 11.2, simple image references are rewritten to use an absolute URL
......
......@@ -31,6 +31,8 @@ module Gitlab
build_duration: build.duration,
build_allow_failure: build.allow_failure,
build_failure_reason: build.failure_reason,
pipeline_id: commit.id,
runner: build_runner(build.runner),
# TODO: do we still need it?
project_id: project.id,
......@@ -43,6 +45,7 @@ module Gitlab
},
commit: {
# note: commit.id is actually the pipeline id
id: commit.id,
sha: commit.sha,
message: commit.git_commit_message,
......@@ -75,6 +78,17 @@ module Gitlab
author = commit.try(:author)
author ? Gitlab::Routing.url_helpers.user_url(author) : "mailto:#{pipeline.git_author_email}"
end
def build_runner(runner)
return unless runner
{
id: runner.id,
description: runner.description,
active: runner.active?,
is_shared: runner.instance_type?
}
end
end
end
end
......@@ -3,7 +3,8 @@
require 'spec_helper'
describe Gitlab::DataBuilder::Build do
let(:build) { create(:ci_build) }
let(:runner) { create(:ci_runner, :instance) }
let(:build) { create(:ci_build, :running, runner: runner) }
describe '.build' do
let(:data) do
......@@ -20,6 +21,10 @@ describe Gitlab::DataBuilder::Build do
it { expect(data[:build_failure_reason]).to eq(build.failure_reason) }
it { expect(data[:project_id]).to eq(build.project.id) }
it { expect(data[:project_name]).to eq(build.project.full_name) }
it { expect(data[:pipeline_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][:description]).to eq(build.runner.description) }
context 'commit author_url' do
context 'when no commit present' do
......
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