diff --git a/changelogs/unreleased/mc-api-pipeline-webhook-remove-retried-jobs.yml b/changelogs/unreleased/mc-api-pipeline-webhook-remove-retried-jobs.yml new file mode 100644 index 0000000000000000000000000000000000000000..f75824b04ceead7ef07a05d2e2d00bb99b650f50 --- /dev/null +++ b/changelogs/unreleased/mc-api-pipeline-webhook-remove-retried-jobs.yml @@ -0,0 +1,5 @@ +--- +title: Send only latest jobs in pipeline webhook payload. +merge_request: 53159 +author: +type: fixed diff --git a/doc/user/project/integrations/webhooks.md b/doc/user/project/integrations/webhooks.md index 27c2cb08d10d10a71c88fe3fe03bbffd60f77047..0cf01adef133d51079c05393ebc64ada923bbc60 100644 --- a/doc/user/project/integrations/webhooks.md +++ b/doc/user/project/integrations/webhooks.md @@ -1029,6 +1029,9 @@ X-Gitlab-Event: Wiki Page Hook ### Pipeline events +In [GitLab 13.9](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/53159) +and later, the pipeline webhook returns only the latest jobs. + Triggered on status change of Pipeline. **Request Header**: diff --git a/lib/gitlab/data_builder/pipeline.rb b/lib/gitlab/data_builder/pipeline.rb index 2413f68f4d047c2b85d1906d50f64bb94f28ffc0..3036bc57ca58e7439ee3b68d6f8a1a1fbdc66741 100644 --- a/lib/gitlab/data_builder/pipeline.rb +++ b/lib/gitlab/data_builder/pipeline.rb @@ -13,7 +13,7 @@ def build(pipeline) user: pipeline.user.try(:hook_attrs), project: pipeline.project.hook_attrs(backward: false), commit: pipeline.commit.try(:hook_attrs), - builds: pipeline.builds.map(&method(:build_hook_attrs)) + builds: pipeline.builds.latest.map(&method(:build_hook_attrs)) } end diff --git a/spec/lib/gitlab/data_builder/pipeline_spec.rb b/spec/lib/gitlab/data_builder/pipeline_spec.rb index 32619fc4c37374708bc5de8e506b9eed4fb62c21..fd7cadeb89ebda836802ddc842673cb65d7a016d 100644 --- a/spec/lib/gitlab/data_builder/pipeline_spec.rb +++ b/spec/lib/gitlab/data_builder/pipeline_spec.rb @@ -104,5 +104,16 @@ expect(merge_request_attrs[:url]).to eq("http://localhost/#{merge_request.target_project.full_path}/-/merge_requests/#{merge_request.iid}") end end + + context 'when pipeline has retried builds' do + before do + create(:ci_build, :retried, pipeline: pipeline) + end + + it 'does not contain retried builds in payload' do + expect(data[:builds].count).to eq(1) + expect(build_data[:id]).to eq(build.id) + end + end end end