Skip to content
Snippets Groups Projects
Commit 41376fac authored by Alexis Kalderimis's avatar Alexis Kalderimis :speech_balloon:
Browse files

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
No related branches found
No related tags found
No related merge requests found
---
title: Added environment details to Job Hook and Pipeline Hook
merge_request: 54480
author: AdrianLC
type: changed
Loading
Loading
@@ -1133,6 +1133,10 @@ X-Gitlab-Event: Pipeline Hook
"artifacts_file":{
"filename": null,
"size": null
},
"environment": {
"name": "production",
"action": "start"
}
},
{
Loading
Loading
@@ -1167,7 +1171,8 @@ X-Gitlab-Event: Pipeline Hook
"artifacts_file":{
"filename": null,
"size": null
}
},
"environment": null
},
{
"id": 378,
Loading
Loading
@@ -1200,7 +1205,8 @@ X-Gitlab-Event: Pipeline Hook
"artifacts_file":{
"filename": null,
"size": null
}
},
"environment": null
},
{
"id": 376,
Loading
Loading
@@ -1233,7 +1239,8 @@ X-Gitlab-Event: Pipeline Hook
"artifacts_file":{
"filename": null,
"size": null
}
},
"environment": null
},
{
"id": 379,
Loading
Loading
@@ -1257,6 +1264,10 @@ X-Gitlab-Event: Pipeline Hook
"artifacts_file":{
"filename": null,
"size": null
},
"environment": {
"name": "staging",
"action": "start"
}
}
]
Loading
Loading
@@ -1329,7 +1340,8 @@ X-Gitlab-Event: Job Hook
"linux",
"docker"
]
}
},
"environment": null
}
```
 
Loading
Loading
Loading
Loading
@@ -62,7 +62,9 @@ def build(build)
git_http_url: project.http_url_to_repo,
git_ssh_url: project.ssh_url_to_repo,
visibility_level: project.visibility_level
}
},
environment: build_environment(build)
}
 
data
Loading
Loading
@@ -86,6 +88,15 @@ def build_runner(runner)
tags: runner.tags&.map(&:name)
}
end
def build_environment(build)
return unless build.has_environment?
{
name: build.expanded_environment_name,
action: build.environment_action
}
end
end
end
end
Loading
Loading
@@ -67,7 +67,8 @@ def build_hook_attrs(build)
artifacts_file: {
filename: build.artifacts_file&.filename,
size: build.artifacts_size
}
},
environment: environment_hook_attrs(build)
}
end
 
Loading
Loading
@@ -80,6 +81,15 @@ def runner_hook_attrs(runner)
tags: runner.tags&.map(&:name)
}
end
def environment_hook_attrs(build)
return unless build.has_environment?
{
name: build.expanded_environment_name,
action: build.environment_action
}
end
end
end
end
Loading
Loading
@@ -38,6 +38,7 @@
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[:environment]).to be_nil }
 
context 'commit author_url' do
context 'when no commit present' do
Loading
Loading
@@ -63,6 +64,13 @@
expect(data[:commit][:author_url]).to eq(Gitlab::Routing.url_helpers.user_url(username: build.commit.author.username))
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
Loading
Loading
@@ -37,6 +37,7 @@
expect(build_data[:id]).to eq(build.id)
expect(build_data[:status]).to eq(build.status)
expect(build_data[:allow_failure]).to eq(build.allow_failure)
expect(build_data[:environment]).to be_nil
expect(runner_data).to eq(nil)
expect(project_data).to eq(project.hook_attrs(backward: false))
expect(data[:merge_request]).to be_nil
Loading
Loading
@@ -115,5 +116,12 @@
expect(build_data[:id]).to eq(build.id)
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment