Accessing CI jobs of a deleted environment results in 500 Internal Server Error
Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.
Summary
Accessing CI jobs of a deleted environment results in 500 Internal Server Error.
Error message on the UI: An error occurred while fetching the job.
Steps to reproduce
- Create an environment. Example name:
staging
. - Deploy something on it via
.gitlab-ci.yml
. I used the below yaml from Defining environments:
Expand for viewing the .gitlab-ci.yml fie
stages: - test - build - deploy test: stage: test script: echo "Running tests" build: stage: build script: echo "Building the app" deploy_staging: stage: deploy script: - echo "Deploy to staging server" environment: name: staging url: https://staging.example.com only: - master
- Run a pipeline.
- Stop and delete the environment.
- Try to access the job that was run previously on the deleted environment.
What is the current bug behavior?
UI returns the error An error occurred while fetching the job.
.
What is the expected correct behavior?
Job details must be shown, at least a useful message.
Relevant logs and/or screenshots
UI:
production.log
Started GET "/root/mr-pipeline/-/jobs/386.json" for 49.37.193.68 at 2020-09-11 06:47:35 +0000
Processing by Projects::JobsController#show as JSON
Parameters: {"namespace_id"=>"root", "project_id"=>"mr-pipeline", "id"=>"386"}
Completed 500 Internal Server Error in 1250ms (ActiveRecord: 135.3ms | Elasticsearch: 0.0ms | Allocations: 516776)
NoMethodError (undefined method `last_deployment' for nil:NilClass):
app/models/deployment.rb:156:in `last?'
lib/gitlab/metrics/instrumentation.rb:161:in `block in last?'
lib/gitlab/metrics/method_call.rb:27:in `measure'
lib/gitlab/metrics/instrumentation.rb:161:in `last?'
app/models/ci/build.rb:967:in `successful_deployment_status'
lib/gitlab/metrics/instrumentation.rb:161:in `block in successful_deployment_status'
lib/gitlab/metrics/method_call.rb:27:in `measure'
lib/gitlab/metrics/instrumentation.rb:161:in `successful_deployment_status'
app/models/ci/build.rb:928:in `deployment_status'
app/serializers/base_serializer.rb:16:in `represent'
app/controllers/projects/jobs_controller.rb:43:in `block (2 levels) in show'
app/controllers/projects/jobs_controller.rb:36:in `show'
ee/lib/gitlab/ip_address_state.rb:10:in `with'
ee/app/controllers/ee/application_controller.rb:44:in `set_current_ip_address'
app/controllers/application_controller.rb:491:in `set_current_admin'
lib/gitlab/session.rb:11:in `with_session'
app/controllers/application_controller.rb:482:in `set_session_storage'
lib/gitlab/i18n.rb:73:in `with_locale'
lib/gitlab/i18n.rb:79:in `with_user_locale'
app/controllers/application_controller.rb:476:in `set_locale'
lib/gitlab/error_tracking.rb:50:in `with_context'
app/controllers/application_controller.rb:541:in `sentry_context'
app/controllers/application_controller.rb:469:in `block in set_current_context'
lib/gitlab/application_context.rb:52:in `block in use'
lib/gitlab/application_context.rb:52:in `use'
lib/gitlab/application_context.rb:20:in `with_context'
app/controllers/application_controller.rb:462:in `set_current_context'
lib/gitlab/metrics/elasticsearch_rack_middleware.rb:16:in `call'
lib/gitlab/middleware/rails_queue_duration.rb:33:in `call'
lib/gitlab/metrics/rack_middleware.rb:16:in `block in call'
lib/gitlab/metrics/transaction.rb:61:in `run'
lib/gitlab/metrics/rack_middleware.rb:16:in `call'
lib/gitlab/request_profiler/middleware.rb:17:in `call'
ee/lib/gitlab/jira/middleware.rb:19:in `call'
lib/gitlab/middleware/go.rb:20:in `call'
lib/gitlab/etag_caching/middleware.rb:13:in `call'
lib/gitlab/middleware/multipart.rb:140:in `call'
lib/gitlab/middleware/read_only/controller.rb:51:in `call'
lib/gitlab/middleware/read_only.rb:18:in `call'
lib/gitlab/middleware/same_site_cookies.rb:27:in `call'
lib/gitlab/middleware/basic_health_check.rb:25:in `call'
lib/gitlab/middleware/handle_ip_spoof_attack_error.rb:25:in `call'
lib/gitlab/middleware/request_context.rb:23:in `call'
config/initializers/fix_local_cache_middleware.rb:9:in `call'
lib/gitlab/metrics/requests_rack_middleware.rb:60:in `call'
lib/gitlab/middleware/release_env.rb:12:in `call'
Results of GitLab environment info
Expand for output related to GitLab environment info
root@psureshbabu-gitlab:~# gitlab-rake gitlab:env:info System information System: Ubuntu 18.04 Proxy: no Current User: git Using RVM: no Ruby Version: 2.6.6p146 Gem Version: 2.7.10 Bundler Version:1.17.3 Rake Version: 12.3.3 Redis Version: 5.0.9 Git Version: 2.28.0 Sidekiq Version:5.2.9 Go Version: unknown GitLab information Version: 13.3.1-ee Revision: f0a10848821 Directory: /opt/gitlab/embedded/service/gitlab-rails DB Adapter: PostgreSQL DB Version: 11.7 URL: https://psureshbabu-gitlab.sr.gitlab.support HTTP Clone URL: https://psureshbabu-gitlab.sr.gitlab.support/some-group/some-project.git SSH Clone URL: git@psureshbabu-gitlab.sr.gitlab.support:some-group/some-project.git Elasticsearch: no Geo: no Using LDAP: no Using Omniauth: yes Omniauth Providers: GitLab Shell Version: 13.6.0 Repository storage paths: - default: /var/opt/gitlab/git-data/repositories GitLab Shell path: /opt/gitlab/embedded/service/gitlab-shell Git: /opt/gitlab/embedded/bin/git
Results of GitLab application Check
Expand for output related to the GitLab application check
root@psureshbabu-gitlab:~# gitlab-rake gitlab:check SANITIZE=true Checking GitLab subtasks ...
Checking GitLab Shell ...
GitLab Shell: ... GitLab Shell version >= 13.6.0 ? ... OK (13.6.0) Running /opt/gitlab/embedded/service/gitlab-shell/bin/check Internal API available: OK Redis available via internal API: OK gitlab-shell self-check successful
Checking GitLab Shell ... Finished
Checking Gitaly ...
Gitaly: ... default ... OK
Checking Gitaly ... Finished
Checking Sidekiq ...
Sidekiq: ... Running? ... yes Number of Sidekiq processes ... 1
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? ... yes 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? ... yes Init script exists? ... skipped (omnibus-gitlab has no init script) Init script up-to-date? ... skipped (omnibus-gitlab has no init script) Projects have namespace: ... 10/1 ... yes 10/2 ... yes 11/3 ... yes 11/4 ... yes 12/5 ... yes 12/6 ... yes 13/7 ... yes 13/8 ... yes 12/9 ... yes 1/10 ... yes 1/11 ... yes 1/12 ... yes 1/13 ... yes 1/14 ... yes 10/15 ... yes 14/16 ... yes 14/17 ... yes 16/18 ... yes 18/20 ... yes 14/21 ... yes 19/22 ... yes 14/23 ... yes 1/24 ... yes 1/26 ... yes 1/27 ... yes 1/28 ... yes 1/29 ... yes 25/30 ... yes 1/31 ... yes 1/32 ... yes Redis version >= 4.0.0? ... yes Ruby version >= 2.5.3 ? ... yes (2.6.6) Git version >= 2.24.0 ? ... yes (2.28.0) Git user has default SSH configuration? ... yes Active users: ... 25 Is authorized keys file accessible? ... yes GitLab configured to store new projects in hashed storage? ... yes All projects are in hashed storage? ... yes Elasticsearch version 6.x - 7.x? ... skipped (elasticsearch is disabled)
Checking GitLab App ... Finished
Checking GitLab subtasks ... Finished