Unable to create environment during deploy with Prevent outdated deployment jobs
Summary
If you deploy to an environment, subsequently delete the environment, and try to run an "older" deployment (relative to last successful for that environment), the following behaviour is observed:
- The job succeeds but does not deploy
- The environment does not get created
- The UI also doesn't show anything when referencing the environment name. Example:
This job is an out-of-date deployment to .
prevent_rollback_deployment
checks the following three conditions are true when preventing the deployment: https://gitlab.com/gitlab-org/gitlab/-/blob/2409d849caa8fcca493866ea9ab6e7e9ce070d8d/app/models/ci/build.rb#L449-452
A deleted deployment should not have a last_deployment
attribute, so the first deployment back to create an environment shouldn't be prevented.
Steps to reproduce
- Create a
.gitlab-ci.yml
file with the following manual deployment job.
stages:
- deploy
deploy:
stage: deploy
script:
- echo lol
environment: prod
when: manual
- Start two pipelines.
- Run the deploy job on the latest pipeline.
- Stop and delete the
prod
environment. - Run the deploy job on the first-created (older) pipeline.
Example Project
https://gitlab.com/gitlab-gold/tmike/zd335708/zd335708/-/jobs/3205743872
What is the current bug behavior?
The deployment job "Passed" but did not deploy. The environment is not created. The job is classified as an out of date deployment job. The UI does not show the environment name, it's blank.
What is the expected correct behavior?
The deployment job should "Pass" and deploy. The environment should be created. The job should not be classified a an out of date deployment job, as it's technically the first deployment for the environment since deletion.
Relevant logs and/or screenshots
Output of checks
Results of GitLab environment info
Expand for output related to GitLab environment info
(For installations with omnibus-gitlab package run and paste the output of: `sudo gitlab-rake gitlab:env:info`) (For installations from source run and paste the output of: `sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production`)
Results of GitLab application Check
Expand for output related to the GitLab application check
(For installations with omnibus-gitlab package run and paste the output of:
sudo gitlab-rake gitlab:check SANITIZE=true
)(For installations from source run and paste the output of:
sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production SANITIZE=true
)(we will only investigate if the tests are passing)
Development next steps
We didn't get very far with refinement phase because this is going to take some digging and no one has that kind of bandwidth for refinement right now. Right now we think it's backend
- replicate this locally and verify the values being checked in this method: https://gitlab.com/gitlab-org/gitlab/-/blob/master/app/models/deployment.rb#L291
- write test that verifies the issue
- update this issue description with proposed solution
- update issue weight (setting to 2 right now as a guess)