Gitlab 服务器端 hooks

服务器端 hooks

Git server hooks

​​​​​​​

 创建全局 Server hooks

https://docs.gitlab.com/ee/administration/server_hooks.html

配置 custom_hooks_dir

            
vim /etc/gitlab/gitlab.rb 

# 这个配置已经作废
gitlab_shell['custom_hooks_dir'] = "/opt/gitlab/embedded/service/gitlab-shell/hooks"

# 在 gitaly 下面加入配置
gitaly['custom_hooks_dir'] = "/var/opt/gitlab/gitaly/custom_hooks"
    
        
        
mkdir -p /var/opt/gitlab/gitaly/custom_hooks
vim /var/opt/gitlab/gitaly/custom_hooks/commit-msg    
chmod +x /var/opt/gitlab/gitaly/custom_hooks/commit-msg
        
        

多个配置可以创建一个 commit-msg.d 目录,然后把多个脚本放入该目录

            
root@netkiller:/opt/gitlab# mkdir -p /var/opt/gitlab/gitaly/custom_hooks/commit-msg.d
root@netkiller:/opt/gitlab# vim /var/
GitLab 的 Server Hooks 可以让你在 GitLab 服务器上的 Git 仓库的特定事件触发时运行脚本。你可以使用这些 Server Hooks 来校验提交的用户名和邮箱。具体的文档如下: 1. 打开 GitLab 服务器上的 Git 仓库,并转到仓库设置页面。 2. 在设置页面,选择“Integrations”选项卡,并找到“Server Hooks”部分。 3. 在“Server Hooks”部分,找到“Custom HTTP POST”选项,并单击“Add webhook”按钮。 4. 在“Add webhook”窗口,输入一个名称和 URL。 URL 应该指向包含你的脚本的服务器端点。 5. 在“Trigger”下拉菜单,选择“Push events”。 6. 在“Secret Token”字段,添加一个令牌以确保只有知道该令牌的人才能访问你的服务器端点。 7. 点击“Add webhook”按钮。 8. 创建一个脚本,校验提交的用户名和邮箱。你可以使用类似以下的 Python 脚本: ```python #!/usr/bin/env python import sys def validate(commit_author_name, commit_author_email): if 'example.com' in commit_author_email: print('Commit rejected: invalid email') return False elif 'John' not in commit_author_name: print('Commit rejected: invalid username') return False else: return True if __name__ == '__main__': commit_author_name = sys.argv[1] commit_author_email = sys.argv[2] if not validate(commit_author_name, commit_author_email): sys.exit(1) ``` 9. 将脚本上传到你的服务器,并确保 GitLab 服务器上的 Git 仓库可以访问该脚本。 10. 确保脚本有执行权限。 11. 提交一个带有无效用户名或邮箱的 commit,以测试你的脚本是否生效。 这样,你就可以使用 Server Hooks 校验提交的用户名和邮箱了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

netkiller-

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值