Create deployments for ready-to-run jobs only
What does this MR do and why?
This change is part of the epic for Reduce main database load by optimizing `deploy... (&10169)
This ensures that deployment records are only created for deploy jobs that are ready to run. This means that deploy jobs that are still at the created
state will not have deployment records upfront, helping to reduce the load on the main database.
For further details, please check the Expected behavior section related issue, and the illustration of the expected behavior in the Screenshots below.
Screenshots or screen recordings
GitLab CI configuration example
Given the following GitLab CI configuration with jobs in different stages:
- [stage-0]
test
job - 4 deploy jobs
- [stage-1]
review
runs automatically aftertest
- [stage-2]
staging
is set aswhen: manual
andallow_failure: false
, meaning it must succeed before jobs in the next stages can run - [stage-3]
canary
is set aswhen: manual
and by defaultallow_failure: true
- [stage-4]
production-a
is set aswhen: manual
(and by defaultallow_failure: true
) - [stage-4]
production-b
is set aswhen: manual
andneeds: [canary]
(and by defaultallow_failure: true
)
- [stage-1]
=== EXPAND THIS SECTION FOR THE GITLAB CI CONFIG ===
stages: [stage-0, stage-1, stage-2, stage-3, stage-4]
test:
stage: stage-0
script: sleep 120
review:
stage: stage-1
environment:
name: review
action: start
script: sleep 60
staging:
stage: stage-2
environment:
name: staging
action: start
script: sleep 60
when: manual
allow_failure: false
canary:
stage: stage-3
environment:
name: canary
action: start
script: exit 0
when: manual
production-a:
stage: stage-4
environment:
name: production-a
action: start
script: exit 0
when: manual
production-b:
stage: stage-4
environment:
name: production-b
action: start
script: exit 0
when: manual
needs: [canary]
Current behavior
This is the behavior before the change in this MR is applied / the Feature Flag is disabled
=== EXPAND THIS SECTION FOR THE EXAMPLE TABLE ===
Expected behavior
This is the expected behavior after the change / the Feature Flag is enabled
=== EXPAND THIS SECTION FOR THE EXAMPLE TABLE ===
Note: since production-b
is set as needs: [canary]
, its corresponding deployment should ideally not be created until canary
succeeds. This will be addressed in a follow-up issue.
How to set up and validate locally
-
Create a project or use an existing project for testing
-
Enable the
create_deployment_only_for_processable_jobs
Feature Flag in the rails consoleFeature.enable(:create_deployment_only_for_processable_jobs)
-
Use the example above for the configuration in your
.gitlab-ci.yml
-
Run the pipeline / observe the running pipeline and verify that it follows the Expected behavior in the example above
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Related to #391291 (closed)