今天升级gitlab 13.3.1升级到14.0.0版本后部分部署过webhook项目的webhook页面显示500,其他没有部署过webhook的项目是正常可以打开的

原因是因为旧的 webhook 与新的 webhook 存在兼容性问题

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
==> /var/log/gitlab/gitlab-rails/production.log <==

ActionView::Template::Error ():
1: %li
2: .row
3: .col-md-8.col-lg-7
4: %strong.light-header= hook.url
5: %div
6: - hook.class.triggers.each_value do |trigger|
7: - if hook.public_send(trigger)

app/views/shared/web_hooks/_hook.html.haml:4
app/views/shared/web_hooks/_index.html.haml:11
app/views/shared/web_hooks/_index.html.haml:10
app/views/projects/hooks/index.html.haml:14
app/controllers/application_controller.rb:128:in `render'
app/controllers/application_controller.rb:487:in `set_current_admin'
lib/gitlab/session.rb:11:in `with_session'
app/controllers/application_controller.rb:478:in `set_session_storage'
lib/gitlab/i18n.rb:99:in `with_locale'
lib/gitlab/i18n.rb:105:in `with_user_locale'
app/controllers/application_controller.rb:472:in `set_locale'
app/controllers/application_controller.rb:466: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/web_transaction.rb:21:in `run'
lib/gitlab/metrics/rack_middleware.rb:16:in `call'
lib/gitlab/middleware/speedscope.rb:13:in `call'
lib/gitlab/request_profiler/middleware.rb:17:in `call'
lib/gitlab/jira/middleware.rb:19:in `call'
lib/gitlab/middleware/go.rb:20:in `call'
lib/gitlab/etag_caching/middleware.rb:21:in `call'
lib/gitlab/middleware/multipart.rb:172:in `call'
lib/gitlab/middleware/read_only/controller.rb:50:in `call'
lib/gitlab/middleware/read_only.rb:18:in `call'
lib/gitlab/middleware/same_site_cookies.rb:27:in `call'
lib/gitlab/middleware/handle_malformed_strings.rb:21: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:21:in `call'
config/initializers/fix_local_cache_middleware.rb:11:in `call'
lib/gitlab/middleware/rack_multipart_tempfile_factory.rb:19:in `call'
lib/gitlab/metrics/requests_rack_middleware.rb:74:in `call'
lib/gitlab/middleware/release_env.rb:12:in `call'

解决办法

由于我webhook里的数据可以重新配置,这里只需恢复webhook页面为正常即可 ,如果需要原数据的话请提前备份原目录下/etc/gitlab/gitlab-secrets.json文件

进入gitlab数据库

1
2
3
4
root@984db48e6398:/# gitlab-rails db
psql (12.6)
Type "help" for help.

查看一下webhook500的项目ID

通过项目ID查出hook的ID

1
2
3
4
5
6
7
gitlabhq_production=> select id from web_hooks where project_id=65;
id
----
35
40
(2 rows)

可以看到我们这里查出了两个ID,分别为35和40,我们分辩不出来索性全部删除

先申请一下项目的令牌tocken

然后退出数据库连接执行api删除操作

1
2
curl --header "Private-Token: 3hDkYwv-xxxxx8nU" -X DELETE http://git.xxxxx.com/api/v4/projects/65/hooks/35
curl --header "Private-Token: 3hDkYwv-xxxxxu8nU" -X DELETE http://git.xxxxx.com/api/v4/projects/65/hooks/40

然后刷新webhook页面即可恢复正常