An environment with no deployment gets created when pipeline has no deployment job but has a job with environment:stop action
Summary
If a pipeline doesn't contain a deployment job but has a job to stop an environment, an environment with no deployment gets created.
Steps to reproduce
- Create a project
- Create a new branch and add
.gitlab-ci.yml
file with below content:
test:
stage: test
script:
- echo "Test"
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
.deploy-rules:
rules:
# Only deploy unprotected branches if the Deploy label is set
- if: $CI_PIPELINE_SOURCE == "merge_request_event" && $CI_COMMIT_REF_PROTECTED == "false" && $CI_MERGE_REQUEST_LABELS =~ /Deploy/
# Always deploy protected branches
- if: ($CI_PIPELINE_SOURCE == "push" || $CI_PIPELINE_SOURCE == "schedule" || $CI_PIPELINE_SOURCE == "web") && $CI_COMMIT_REF_PROTECTED == "true" && $CI_SCHEDULE_CONTAINERS == null
deploy_staging:
stage: deploy
extends: .deploy-rules
script:
- echo "Deploy to staging server"
environment:
name: staging/$CI_COMMIT_REF_NAME
url: https://$CI_ENVIRONMENT_SLUG.example.com
on_stop: staging-stop-review
staging-stop-review:
stage: deploy
# extends: .deploy-rules
script:
- echo "stopped environment"
when: manual
environment:
name: staging/$CI_COMMIT_REF_NAME
action: stop
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
- Create a new merge request to merge the new branch into
main
. - Merge request pipeline runs, it has the test job and
staging-stop-review
job. Nodeploy_staging
job. - Go to Operate - Environments. An environment named
staging/<$CI_COMMIT_REF_NAME>
is active and has a text that saysThere are no deployments for this environment yet. Learn more about setting up deployments.
Example Project
https://gitlab.com/e_munn_ultimate_group/tests/environment-test
What is the current bug behavior?
When there is no deployment job in the pipeline, an environment gets created saying there are no deployments yet.
What is the expected correct behavior?
Environment should be created only when deployment job runs.
Relevant logs and/or screenshots
Output of checks
This bug happens on GitLab.com
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)