Commit 41376fac authored by Alex Kalderimis's avatar Alex Kalderimis

Merge branch 'build-hooks-add-deployed-environment' into 'master'

Add environment attrs to build & pipeline hooks

See merge request gitlab-org/gitlab!54480
parents ecdb95a8 826c7cdf
---
title: Added environment details to Job Hook and Pipeline Hook
merge_request: 54480
author: AdrianLC
type: changed
...@@ -1133,6 +1133,10 @@ X-Gitlab-Event: Pipeline Hook ...@@ -1133,6 +1133,10 @@ X-Gitlab-Event: Pipeline Hook
"artifacts_file":{ "artifacts_file":{
"filename": null, "filename": null,
"size": null "size": null
},
"environment": {
"name": "production",
"action": "start"
} }
}, },
{ {
...@@ -1167,7 +1171,8 @@ X-Gitlab-Event: Pipeline Hook ...@@ -1167,7 +1171,8 @@ X-Gitlab-Event: Pipeline Hook
"artifacts_file":{ "artifacts_file":{
"filename": null, "filename": null,
"size": null "size": null
} },
"environment": null
}, },
{ {
"id": 378, "id": 378,
...@@ -1200,7 +1205,8 @@ X-Gitlab-Event: Pipeline Hook ...@@ -1200,7 +1205,8 @@ X-Gitlab-Event: Pipeline Hook
"artifacts_file":{ "artifacts_file":{
"filename": null, "filename": null,
"size": null "size": null
} },
"environment": null
}, },
{ {
"id": 376, "id": 376,
...@@ -1233,7 +1239,8 @@ X-Gitlab-Event: Pipeline Hook ...@@ -1233,7 +1239,8 @@ X-Gitlab-Event: Pipeline Hook
"artifacts_file":{ "artifacts_file":{
"filename": null, "filename": null,
"size": null "size": null
} },
"environment": null
}, },
{ {
"id": 379, "id": 379,
...@@ -1257,6 +1264,10 @@ X-Gitlab-Event: Pipeline Hook ...@@ -1257,6 +1264,10 @@ X-Gitlab-Event: Pipeline Hook
"artifacts_file":{ "artifacts_file":{
"filename": null, "filename": null,
"size": null "size": null
},
"environment": {
"name": "staging",
"action": "start"
} }
} }
] ]
...@@ -1329,7 +1340,8 @@ X-Gitlab-Event: Job Hook ...@@ -1329,7 +1340,8 @@ X-Gitlab-Event: Job Hook
"linux", "linux",
"docker" "docker"
] ]
} },
"environment": null
} }
``` ```
......
...@@ -62,7 +62,9 @@ module Gitlab ...@@ -62,7 +62,9 @@ module Gitlab
git_http_url: project.http_url_to_repo, git_http_url: project.http_url_to_repo,
git_ssh_url: project.ssh_url_to_repo, git_ssh_url: project.ssh_url_to_repo,
visibility_level: project.visibility_level visibility_level: project.visibility_level
} },
environment: build_environment(build)
} }
data data
...@@ -86,6 +88,15 @@ module Gitlab ...@@ -86,6 +88,15 @@ module Gitlab
tags: runner.tags&.map(&:name) tags: runner.tags&.map(&:name)
} }
end end
def build_environment(build)
return unless build.has_environment?
{
name: build.expanded_environment_name,
action: build.environment_action
}
end
end end
end end
end end
...@@ -67,7 +67,8 @@ module Gitlab ...@@ -67,7 +67,8 @@ module Gitlab
artifacts_file: { artifacts_file: {
filename: build.artifacts_file&.filename, filename: build.artifacts_file&.filename,
size: build.artifacts_size size: build.artifacts_size
} },
environment: environment_hook_attrs(build)
} }
end end
...@@ -80,6 +81,15 @@ module Gitlab ...@@ -80,6 +81,15 @@ module Gitlab
tags: runner.tags&.map(&:name) tags: runner.tags&.map(&:name)
} }
end end
def environment_hook_attrs(build)
return unless build.has_environment?
{
name: build.expanded_environment_name,
action: build.environment_action
}
end
end end
end end
end end
...@@ -38,6 +38,7 @@ RSpec.describe Gitlab::DataBuilder::Build do ...@@ -38,6 +38,7 @@ RSpec.describe Gitlab::DataBuilder::Build do
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][: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) }
it { expect(data[:environment]).to be_nil }
context 'commit author_url' do context 'commit author_url' do
context 'when no commit present' do context 'when no commit present' do
...@@ -63,6 +64,13 @@ RSpec.describe Gitlab::DataBuilder::Build do ...@@ -63,6 +64,13 @@ RSpec.describe Gitlab::DataBuilder::Build do
expect(data[:commit][:author_url]).to eq(Gitlab::Routing.url_helpers.user_url(username: build.commit.author.username)) expect(data[:commit][:author_url]).to eq(Gitlab::Routing.url_helpers.user_url(username: build.commit.author.username))
end end
end end
context 'with environment' do
let(:build) { create(:ci_build, :teardown_environment) }
it { expect(data[:environment][:name]).to eq(build.expanded_environment_name) }
it { expect(data[:environment][:action]).to eq(build.environment_action) }
end
end end
end end
end end
...@@ -37,6 +37,7 @@ RSpec.describe Gitlab::DataBuilder::Pipeline do ...@@ -37,6 +37,7 @@ RSpec.describe Gitlab::DataBuilder::Pipeline do
expect(build_data[:id]).to eq(build.id) expect(build_data[:id]).to eq(build.id)
expect(build_data[:status]).to eq(build.status) expect(build_data[:status]).to eq(build.status)
expect(build_data[:allow_failure]).to eq(build.allow_failure) expect(build_data[:allow_failure]).to eq(build.allow_failure)
expect(build_data[:environment]).to be_nil
expect(runner_data).to eq(nil) expect(runner_data).to eq(nil)
expect(project_data).to eq(project.hook_attrs(backward: false)) expect(project_data).to eq(project.hook_attrs(backward: false))
expect(data[:merge_request]).to be_nil expect(data[:merge_request]).to be_nil
...@@ -115,5 +116,12 @@ RSpec.describe Gitlab::DataBuilder::Pipeline do ...@@ -115,5 +116,12 @@ RSpec.describe Gitlab::DataBuilder::Pipeline do
expect(build_data[:id]).to eq(build.id) expect(build_data[:id]).to eq(build.id)
end end
end end
context 'build with environment' do
let!(:build) { create(:ci_build, :teardown_environment, pipeline: pipeline) }
it { expect(build_data[:environment][:name]).to eq(build.expanded_environment_name) }
it { expect(build_data[:environment][:action]).to eq(build.environment_action) }
end
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