Fix duplicate environment name causes pipeline creation failure
What does this MR do?
The MR, which was recently shipped in 12.4, contained a bug as reported in #34444 (closed). When there are duplicate environment:name
in the same pipeline (.gitlab-ci.yml), the pipeline fails to be persisted because of the unique constraint on the environment.name
.
For example, in the following .gitlab-ci.yml, pipeline cannot be created.
deploy:
environment: production
deploy-2:
environment: production
Because, there are two jobs point to the same environment production
. CreatePipelineService
tries to save multiple Environment.new(name: 'production', project: project)
and violates uniqueness: { scope: :project_id }
validation. The unpersisted environment
object is assigned to a deployment
object and results in NotNullViolation
on environment_id
.
On the other hand, typical review app workflows are unaffected, as stop-review doesn't create environment object as action: stop
.
review:
environment:
name: review/$CI_COMMIT_REF_NAME
on_stop: stop-review
stop-review:
environment:
name: review/$CI_COMMIT_REF_NAME
action: stop
This behavior was reproduced on staging. https://staging.gitlab.com/dosuken123/deployment-iid-test/merge_requests/3/diffs => https://sentry.gitlab.net/gitlab/staginggitlabcom/issues/1022739/?query=is:unresolved.
Close #34444 (closed)
Does this MR meet the acceptance criteria?
Conformity
-
Changelog entry - [-] Documentation created/updated or follow-up review issue created
-
Code review guidelines -
Merge request performance guidelines -
Style guides -
Database guides - [-] Separation of EE specific content
Availability and Testing
-
Review and add/update tests for this feature/bug. Consider all test levels. See the Test Planning Process. - [-] Tested in all supported browsers
Security
If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:
- [-] Label as security and @ mention
@gitlab-com/gl-security/appsec
- [-] The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
- [-] Security reports checked/validated by a reviewer from the AppSec team