Deployments->Environments displays wrong commit refs/tags
Summary
The deployments->environments overview page at https://your_gitlab_url/PROJECT/-/environments displays the wrong "Commit". It should display the commit that is currently deployed. Instead, from all the commits that so far have been deployed to an environment, GitLab picks the latest commit in the git graph.
Steps to reproduce
- create & push
commit 1
- create & push
commit 2
(as a successor ofcommit 1
) - deploy
commit 2
to environmentx
- deploy
commit 1
to environmentx
- go to https://your_gitlab_url/PROJECT/-/environments
- observe that environment
x
is linked tocommit 2
rather thancommit 1
!🐛
What is the expected correct behavior?
environment x
should be linked to commit 1
, which is the one that was last deployed.
Relevant logs and/or screenshots
In this example, commit/tag v18
is the one that should be displayed:
Output of checks
This bug happens on our self-hosted GitLab Enterprise Edition 14.3.0-ee.
Results of GitLab environment info
Expand for output related to GitLab environment info
$ gitlab-rake gitlab:env:info System information System: Proxy: no Current User: git Using RVM: no Ruby Version: 2.7.4p191 Gem Version: 3.2.19 Bundler Version:2.2.19 Rake Version: 13.0.6 Redis Version: unknown Git Version: unknown Sidekiq Version:5.2.9 Go Version: unknown GitLab information Version: 14.3.0-ee Revision: dec73e99fdd Directory: /srv/gitlab DB Adapter: PostgreSQL DB Version: 12.7 URL: https://gitlab.meteotest.ch HTTP Clone URL: https://gitlab.meteotest.ch/some-group/some-project.git SSH Clone URL: git@gitlab.meteotest.ch:some-group/some-project.git Elasticsearch: yes Geo: no Using LDAP: no Using Omniauth: yes Omniauth Providers: google_oauth2 GitLab Shell Version: 13.21.0 Repository storage paths: - default: /var/opt/gitlab/repo GitLab Shell path: /home/git/gitlab-shell Git: /usr/bin/git
Results of GitLab application Check
Expand for output related to the GitLab application check
$ gitlab-rake gitlab:check SANITIZE=true Checking GitLab subtasks ...Checking GitLab Shell ...
GitLab Shell: ... GitLab Shell version >= 13.21.0 ? ... OK (13.21.0) Running /home/git/gitlab-shell/bin/check gitlab-shell self-check failed Try fixing it: Make sure GitLab is running; Check the gitlab-shell configuration file: sudo -u git -H editor /home/git/gitlab-shell/config.yml Please fix the error above and rerun the checks.
Checking GitLab Shell ... Finished
Checking Gitaly ...
Gitaly: ... default ... OK
Checking Gitaly ... Finished
Checking Sidekiq ...
Sidekiq: ... Running? ... no Try fixing it: sudo -u git -H RAILS_ENV=production bin/background_jobs start For more information see: doc/install/installation.md in section "Install Init Script" see log/sidekiq.log for possible errors Please fix the error above and rerun the checks.
Checking Sidekiq ... Finished
Checking Incoming Email ...
Incoming Email: ... Reply by email is disabled in config/gitlab.yml
Checking Incoming Email ... Finished
Checking LDAP ...
LDAP: ... LDAP is disabled in config/gitlab.yml
Checking LDAP ... Finished
Checking GitLab App ...
Git configured correctly? ... no Trying to fix error automatically. ...Failed Try fixing it: sudo -u git -H "/usr/bin/git" config --global core.autocrlf "input" For more information see: doc/install/installation.md in section "GitLab" Database config exists? ... yes All migrations up? ... yes Database contains orphaned GroupMembers? ... no GitLab config exists? ... yes GitLab config up to date? ... yes Log directory writable? ... yes Tmp directory writable? ... yes Uploads directory exists? ... yes Uploads directory has correct permissions? ... yes Uploads directory tmp has correct permissions? ... skipped (no tmp uploads folder yet) Init script exists? ... no Try fixing it: Install the init script For more information see: doc/install/installation.md in section "Install Init Script" Please fix the error above and rerun the checks. Init script up-to-date? ... can't check because of previous errors Projects have namespace: ... 13/1 ... yes 3/9 ... yes 30/12 ... yes 13/14 ... yes 13/15 ... yes 13/17 ... yes 30/18 ... yes 30/33 ... yes 30/34 ... yes 13/35 ... yes 30/38 ... yes 30/39 ... yes 13/40 ... yes 30/41 ... yes 13/46 ... yes 30/51 ... yes 30/52 ... yes 30/53 ... yes 13/54 ... yes 13/55 ... yes 13/57 ... yes 13/58 ... yes 13/59 ... yes 30/64 ... yes 13/66 ... yes 30/68 ... yes 30/70 ... yes 13/71 ... yes 30/73 ... yes 13/74 ... yes 30/75 ... yes 30/76 ... yes 30/79 ... yes 30/80 ... yes 13/81 ... yes 13/87 ... yes 30/90 ... yes 13/94 ... yes 13/99 ... yes 30/100 ... yes 13/101 ... yes 30/103 ... yes 13/104 ... yes 13/105 ... yes 13/106 ... yes 30/107 ... yes 30/108 ... yes 76/112 ... yes 13/113 ... yes 30/114 ... yes 30/115 ... yes 30/116 ... yes 30/117 ... yes 21/118 ... yes 21/119 ... yes 30/120 ... yes 21/121 ... yes 30/123 ... yes 13/124 ... yes 21/125 ... yes 21/126 ... yes 30/127 ... yes 13/128 ... yes 30/129 ... yes 30/130 ... yes 30/132 ... yes 30/133 ... yes 13/134 ... yes 21/135 ... yes 30/136 ... yes 30/137 ... yes 30/139 ... yes 30/140 ... yes 30/141 ... yes 30/142 ... yes 30/144 ... yes 30/145 ... yes 13/147 ... yes 13/148 ... yes 30/150 ... yes 13/151 ... yes 76/152 ... yes 13/153 ... yes 21/154 ... yes 30/155 ... yes 13/156 ... yes 30/158 ... yes 13/159 ... yes 25/162 ... yes 30/163 ... yes 30/165 ... yes 13/166 ... yes 13/170 ... yes 30/172 ... yes 30/173 ... yes 13/174 ... yes 13/175 ... yes 13/176 ... yes 13/178 ... yes 31/182 ... yes 13/183 ... yes 30/188 ... yes 13/189 ... yes 21/190 ... yes 30/192 ... yes 13/193 ... yes 23/194 ... yes 13/197 ... yes 30/198 ... yes 30/199 ... yes 30/200 ... yes 13/201 ... yes 30/203 ... yes 30/204 ... yes 87/205 ... yes 87/206 ... yes 87/207 ... yes 87/208 ... yes 87/209 ... yes 87/210 ... yes 30/211 ... yes 87/212 ... yes 13/213 ... yes 87/214 ... yes 87/215 ... yes 87/216 ... yes 87/217 ... yes 13/219 ... yes 30/220 ... yes 13/221 ... yes 31/222 ... yes 87/223 ... yes 87/224 ... yes 13/225 ... yes 13/226 ... yes 13/227 ... yes 13/234 ... yes 13/243 ... yes 30/244 ... yes 30/249 ... yes 30/250 ... yes 30/251 ... yes 30/252 ... yes 13/254 ... yes 31/255 ... yes 13/256 ... yes 30/259 ... yes 33/262 ... yes 13/264 ... yes 53/266 ... yes 52/268 ... yes 53/272 ... yes 53/273 ... yes 51/275 ... yes 52/277 ... yes 13/278 ... yes 87/279 ... yes 33/281 ... yes 33/282 ... yes 33/283 ... yes 13/284 ... yes 30/285 ... yes 33/286 ... yes 13/287 ... yes 30/290 ... yes 87/291 ... yes 87/292 ... yes 21/293 ... yes 57/294 ... yes 57/295 ... yes 57/296 ... yes 13/298 ... yes 30/299 ... yes 13/300 ... yes 23/303 ... yes 13/304 ... yes 30/305 ... yes 13/306 ... yes 30/307 ... yes 60/309 ... yes 13/310 ... yes 30/311 ... yes 8/312 ... yes 8/313 ... yes 52/314 ... yes 13/316 ... yes 21/317 ... yes 60/318 ... yes 13/319 ... yes 30/320 ... yes 13/322 ... yes 30/323 ... yes 4/325 ... yes 21/326 ... yes 30/327 ... yes 30/328 ... yes 30/329 ... yes 61/331 ... yes 13/332 ... yes 30/333 ... yes 13/334 ... yes 13/336 ... yes 30/337 ... yes 13/338 ... yes 13/339 ... yes 13/341 ... yes 21/342 ... yes 13/344 ... yes 13/345 ... yes 13/346 ... yes 30/347 ... yes 28/352 ... yes 13/353 ... yes 30/354 ... yes 30/355 ... yes 13/356 ... yes 30/358 ... yes 30/359 ... yes 13/360 ... yes 30/361 ... yes 13/362 ... yes 65/367 ... yes 65/368 ... yes 65/369 ... yes 65/370 ... yes 65/371 ... yes 65/373 ... yes 31/374 ... yes 13/375 ... yes 60/376 ... yes 13/377 ... yes 21/378 ... yes 13/379 ... yes 31/380 ... yes 31/381 ... yes 13/383 ... yes 30/384 ... yes 87/388 ... yes 72/392 ... yes 73/393 ... yes 73/394 ... yes 73/395 ... yes 73/396 ... yes 73/397 ... yes 73/398 ... yes 73/399 ... yes 73/400 ... yes 73/401 ... yes 73/402 ... yes 13/403 ... yes 13/404 ... yes 30/405 ... yes 13/406 ... yes 60/407 ... yes 30/412 ... yes 76/414 ... yes 60/416 ... yes 60/417 ... yes 13/420 ... yes 74/422 ... yes 13/424 ... yes 30/425 ... yes 13/426 ... yes 60/427 ... yes 72/431 ... yes 72/432 ... yes 13/433 ... yes 60/434 ... yes 13/435 ... yes 76/436 ... yes 76/437 ... yes 76/438 ... yes 13/442 ... yes 30/443 ... yes 13/444 ... yes 13/477 ... yes 13/478 ... yes 61/480 ... yes 13/481 ... yes 13/482 ... yes 30/483 ... yes 72/484 ... yes 62/486 ... yes 62/487 ... yes 13/489 ... yes 13/490 ... yes 31/491 ... yes 31/493 ... yes 65/494 ... yes 62/495 ... yes 31/497 ... yes 51/498 ... yes 84/500 ... yes 84/501 ... yes 13/502 ... yes 60/504 ... yes 30/505 ... yes 75/507 ... yes 13/508 ... yes 86/509 ... yes 75/510 ... yes 60/513 ... yes 75/514 ... yes 21/515 ... yes 70/518 ... yes 75/519 ... yes 83/520 ... yes 76/521 ... yes 76/522 ... yes 13/523 ... yes 84/525 ... yes 99/526 ... yes 31/527 ... yes 13/529 ... yes 31/530 ... yes 31/531 ... yes 60/533 ... yes 13/534 ... yes 13/536 ... yes 74/537 ... yes 31/538 ... yes 31/540 ... yes 101/541 ... yes 31/544 ... yes 84/545 ... yes 84/546 ... yes 31/547 ... yes 113/549 ... yes 113/550 ... yes 113/551 ... yes 113/552 ... yes 113/553 ... yes 113/554 ... yes 113/555 ... yes 113/556 ... yes 114/557 ... yes 112/558 ... yes 112/559 ... yes 112/560 ... yes 112/561 ... yes 112/562 ... yes 112/563 ... yes 112/564 ... yes 112/565 ... yes 112/566 ... yes 112/567 ... yes 112/568 ... yes 112/569 ... yes 112/570 ... yes 112/571 ... yes 112/572 ... yes 112/573 ... yes 112/574 ... yes 115/575 ... yes 62/576 ... yes 62/578 ... yes 100/579 ... yes 31/580 ... yes 117/581 ... yes 31/582 ... yes 119/583 ... yes 13/584 ... yes 112/586 ... yes 60/587 ... yes 31/588 ... yes 101/589 ... yes 121/590 ... yes 31/593 ... yes 84/594 ... yes 75/595 ... yes 75/596 ... yes 13/597 ... yes 51/598 ... yes 53/600 ... yes 31/601 ... yes 31/602 ... yes 13/603 ... yes 13/604 ... yes 53/605 ... yes 127/606 ... yes 129/607 ... yes 62/609 ... yes 62/610 ... yes 62/611 ... yes 62/613 ... yes 62/614 ... yes 62/615 ... yes 62/616 ... yes 62/617 ... yes 62/618 ... yes 62/619 ... yes 62/620 ... yes 62/621 ... yes 62/622 ... yes 62/623 ... yes 62/624 ... yes 62/626 ... yes 62/627 ... yes 62/628 ... yes 62/629 ... yes 62/630 ... yes 62/631 ... yes 62/632 ... yes 13/633 ... yes 13/634 ... yes 62/635 ... yes Redis version >= 5.0.0? ... yes Ruby version >= 2.7.2 ? ... yes (2.7.4) Git version >= 2.31.0 ? ... no Your git bin path is "/usr/bin/git" Try fixing it: Update your git to a version >= 2.31.0 from Unknown Please fix the error above and rerun the checks. Git user has default SSH configuration? ... yes Active users: ... 40 Is authorized keys file accessible? ... skipped (authorized keys not enabled) GitLab configured to store new projects in hashed storage? ... yes All projects are in hashed storage? ... yes Elasticsearch version 7.x (6.4 - 6.x deprecated to be removed in 13.8)? ... yes (6.8.13)
Checking GitLab App ... Finished
Checking GitLab subtasks ... Finished
Implementation plan
This is an ordering issue with Environment#last_deployment
. To fix this, we could order deployments by finished_at
. Example:
diff --git a/app/models/environment.rb b/app/models/environment.rb
index 450ed6206d5..ae204fa1ae2 100644
--- a/app/models/environment.rb
+++ b/app/models/environment.rb
@@ -26,7 +26,7 @@ class Environment < ApplicationRecord
has_many :self_managed_prometheus_alert_events, inverse_of: :environment
has_many :alert_management_alerts, class_name: 'AlertManagement::Alert', inverse_of: :environment
- has_one :last_deployment, -> { success.distinct_on_environment }, class_name: 'Deployment', inverse_of: :environment
+ has_one :last_deployment, -> { success.ordered }, class_name: 'Deployment', inverse_of: :environment
has_one :last_visible_deployment, -> { visible.distinct_on_environment }, inverse_of: :environment, class_name: 'Deployment'
has_one :last_visible_deployable, through: :last_visible_deployment, source: 'deployable', source_type: 'CommitStatus', disable_joins: true
has_one :last_visible_pipeline, through: :last_visible_deployable, source: 'pipeline', disable_joins: true
It may be worth looking into other uses of distinct_on_environment
to see if they have similar ordering issues.