Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
826c7cdf
Commit
826c7cdf
authored
Feb 22, 2021
by
Adrián López Calvo
Committed by
Alex Kalderimis
Feb 22, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add environment attrs to build & pipeline hooks
parent
8de5fa44
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
60 additions
and
6 deletions
+60
-6
changelogs/unreleased/add-environment-job-pipeline-hooks.yml
changelogs/unreleased/add-environment-job-pipeline-hooks.yml
+5
-0
doc/user/project/integrations/webhooks.md
doc/user/project/integrations/webhooks.md
+16
-4
lib/gitlab/data_builder/build.rb
lib/gitlab/data_builder/build.rb
+12
-1
lib/gitlab/data_builder/pipeline.rb
lib/gitlab/data_builder/pipeline.rb
+11
-1
spec/lib/gitlab/data_builder/build_spec.rb
spec/lib/gitlab/data_builder/build_spec.rb
+8
-0
spec/lib/gitlab/data_builder/pipeline_spec.rb
spec/lib/gitlab/data_builder/pipeline_spec.rb
+8
-0
No files found.
changelogs/unreleased/add-environment-job-pipeline-hooks.yml
0 → 100644
View file @
826c7cdf
---
title
:
Added environment details to Job Hook and Pipeline Hook
merge_request
:
54480
author
:
AdrianLC
type
:
changed
doc/user/project/integrations/webhooks.md
View file @
826c7cdf
...
@@ -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
}
}
```
```
...
...
lib/gitlab/data_builder/build.rb
View file @
826c7cdf
...
@@ -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
lib/gitlab/data_builder/pipeline.rb
View file @
826c7cdf
...
@@ -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
spec/lib/gitlab/data_builder/build_spec.rb
View file @
826c7cdf
...
@@ -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
spec/lib/gitlab/data_builder/pipeline_spec.rb
View file @
826c7cdf
...
@@ -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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment