Support security mirror for release environment notification
What does this MR do and why?
Describe in detail what your merge request does and why.
Content
- Support security mirror for release environment notification
- Support QA jobs running in parallel - so search for the first failed QA job, instead of only one by its name
- Create
ReleaseEnvironment::BaseNotifier
to share common methods
The Release Environments pipeline now also runs on the security mirror (gitlab-org/security/gitlab), so this commit supports the release environment notifier to search for the bridge pipeline in security mirror, by adding a new argument mirror
. Read the issue gitlab-com/gl-infra/delivery#20333 (closed) to know more details about the problem before this change.
Note that, this change should also come with a change in the Release Environments pipeline, to trigger the notification pipeline in release-tools
with the new additional argument mirror
.
Ref: gitlab-com/gl-infra/delivery#20333 (closed)
Testing
DeployNotifier
with a wrong mirror
Test ReleaseTools::ReleaseEnvironment::DeployNotifier.new(pipeline_id: 1350199732, environment_name: "dat-test", release_environment_version: "a-test-version", mirror: "secur").execute
ArgumentError: Invalid mirror: secur
DeployNotifier
with security
mirror
Test [1] pry(main)> ReleaseTools::ReleaseEnvironment::DeployNotifier.new(pipeline_id: 1350199732, environment_name: "dat-test", release_environment_version: "a-test-version", mirror: "security").execute
2024-06-27 21:52:33.798322 D ReleaseTools::ReleaseEnvironment::DeployNotifier -- Executing release environment notifier -- {:pipeline_id=>1350199732, :environment_name=>"dat-test", :release_environment_version=>"a-test-version"}
2024-06-27 21:52:33.798347 I ReleaseTools::ReleaseEnvironment::DeployNotifier -- Fetch downstream pipeline -- {:pipeline_id=>1350199732}
2024-06-27 21:52:33.798351 I ReleaseTools::ReleaseEnvironment::DeployNotifier -- Fetching bridge from pipeline -- {:pipeline_id=>1350199732}
2024-06-27 21:52:34.375403 D ReleaseTools::GitlabSecurityClient -- [HTTParty] [2024-06-27 21:52:34 +0200] 200 "GET https://gitlab.com/api/v4/projects/gitlab-org%2Fsecurity%2Fgitlab/pipelines/1350199732/bridges" -
2024-06-27 21:52:34.375925 I ReleaseTools::ReleaseEnvironment::DeployNotifier -- Downstream pipeline found -- {:pipeline_url=>"https://gitlab.com/gitlab-com/gl-infra/release-environments/-/pipelines/1350401158"}
2024-06-27 21:52:34.379164 I ReleaseTools::Slack::ReleaseEnvironment::DeployNotification -- Sending slack notification -- {:pipeline=>"https://gitlab.com/gitlab-com/gl-infra/release-environments/-/pipelines/1350401158", :environment_name=>"dat-test", :release_environment_version=>"a-test-version", :slack_channel=>"C047XHV7PQQ"}
=> {"ok"=>true,
"channel"=>"C047XHV7PQQ",
"ts"=>"1719517954.675309",
"message"=>
{"user"=>"U038VKHEWDN",
"type"=>"message",
"ts"=>"1719517954.675309",
"bot_id"=>"B037Z751MNJ",
"app_id"=>"A0385PGTMSQ",
"text"=>"Release environment dat-test: finished a-test-version",
"team"=>"T02592416",
"bot_profile"=>
{"id"=>"B037Z751MNJ",
"app_id"=>"A0385PGTMSQ",
"name"=>"Release-Tools",
"icons"=>
{"image_36"=>"https://avatars.slack-edge.com/2022-04-07/3381895602368_6f294b6e6a7bde5dcd73_36.png",
"image_48"=>"https://avatars.slack-edge.com/2022-04-07/3381895602368_6f294b6e6a7bde5dcd73_48.png",
"image_72"=>"https://avatars.slack-edge.com/2022-04-07/3381895602368_6f294b6e6a7bde5dcd73_72.png"},
"deleted"=>false,
"updated"=>1649332946,
"team_id"=>"T02592416"},
"blocks"=>
[{"type"=>"section",
"block_id"=>"mRO7H",
"text"=>{"type"=>"mrkdwn", "text"=>":ci_passing: Release Environment *dat-test* <https://gitlab.com/gitlab-com/gl-infra/release-environments/-/pipelines/1350401158|finished> `a-test-version`", "verbatim"=>false}},
{"type"=>"context", "block_id"=>"q9ysa", "elements"=>[{"type"=>"mrkdwn", "text"=>":clock1: 2024-06-27 19:52 UTC", "verbatim"=>false}, {"type"=>"mrkdwn", "text"=>":timer_clock: 10 hours", "verbatim"=>false}]}]}}
QaNotifier
with security
mirror
Test [2] pry(main)> ReleaseTools::ReleaseEnvironment::QaNotifier.new(pipeline_id: 1350199732, environment_name: "dat-test-security", release_environment_version: "a-test-version", mirror: "security").execute
2024-07-02 20:27:14.334285 D ReleaseTools::ReleaseEnvironment::QaNotifier -- Executing release environment QA notifier -- {:pipeline_id=>1350199732, :environment_name=>"dat-test-security", :release_environment_version=>"a-test-version", :mirror=>"security"}
2024-07-02 20:27:14.334312 I ReleaseTools::ReleaseEnvironment::QaNotifier -- Fetching QA jobs from pipeline -- {:pipeline_id=>1350199732}
#<Enumerator::Lazy:0x000000012b3fea68>
2024-07-02 20:27:14.951406 D ReleaseTools::GitlabClient -- [HTTParty] [2024-07-02 20:27:14 +0200] 200 "GET https://gitlab.com/api/v4/projects/gitlab-org%2Fsecurity%2Fgitlab/pipelines/1350199732/jobs" -
2024-07-02 20:27:15.607415 D ReleaseTools::GitlabClient -- [HTTParty] [2024-07-02 20:27:15 +0200] 200 "GET https://gitlab.com/api/v4/projects/gitlab-org%2Fsecurity%2Fgitlab/pipelines/1350199732/jobs" -
2024-07-02 20:27:15.608174 I ReleaseTools::ReleaseEnvironment::QaNotifier -- QA job found -- {:pipeline_url=>"https://gitlab.com/gitlab-org/security/gitlab/-/jobs/7199692638"}
2024-07-02 20:27:15.608209 I ReleaseTools::Slack::ReleaseEnvironment::QaNotification -- Sending slack notification -- {:job=>"https://gitlab.com/gitlab-org/security/gitlab/-/jobs/7199692638", :environment_name=>"dat-test-security", :release_environment_version=>"a-test-version", :slack_channel=>"C047XHV7PQQ"}
=> {"ok"=>true,
"channel"=>"C047XHV7PQQ",
"ts"=>"1719944835.889389",
"message"=>
{"user"=>"U038VKHEWDN",
"type"=>"message",
"ts"=>"1719944835.889389",
"bot_id"=>"B037Z751MNJ",
"app_id"=>"A0385PGTMSQ",
"text"=>"QA Release Environment dat-test-security: failed a-test-version",
"team"=>"T02592416",
"bot_profile"=>
{"id"=>"B037Z751MNJ",
"app_id"=>"A0385PGTMSQ",
"name"=>"Release-Tools",
"icons"=>{"image_36"=>"https://avatars.slack-edge.com/2022-04-07/3381895602368_6f294b6e6a7bde5dcd73_36.png", "image_48"=>"https://avatars.slack-edge.com/2022-04-07/3381895602368_6f294b6e6a7bde5dcd73_48.png", "image_72"=>"https://avatars.slack-edge.com/2022-04-07/3381895602368_6f294b6e6a7bde5dcd73_72.png"},
"deleted"=>false,
"updated"=>1649332946,
"team_id"=>"T02592416"},
"blocks"=>[{"type"=>"section", "block_id"=>"J8a0s", "text"=>{"type"=>"mrkdwn", "text"=>":ci_failing: QA Release Environment *dat-test-security* <https://gitlab.com/gitlab-org/security/gitlab/-/jobs/7199692638|failed> `a-test-version`", "verbatim"=>false}}, {"type"=>"context", "block_id"=>"A0KS1", "elements"=>[{"type"=>"mrkdwn", "text"=>":clock1: 2024-07-02 18:27 UTC", "verbatim"=>false}]}]}}
Edited by Dat Tang