JustNote
  • Introduction
  • DesignPattern
    • 七大原则
      • 开闭原则(OCP)
      • 依赖倒置原则(DIP)
      • 单一职责原则(SRP)
      • 接口隔离原则(ISP)
      • 迪米特法则(LoD)
      • 里氏代换原则(LSP)
      • 合成复用原则(CRP)
    • 创建型模式
      • 简单工厂模式
      • 工厂方法模式
      • 抽象工厂模式
      • 建造者模式
      • 单例模式
      • 原型模式
    • 结构型模式
      • 外观模式
      • 装饰模式
      • 适配器模式
      • 享元模式
      • 组合模式
      • 桥接模式
      • 代理模式
    • 行为型模式
      • 模板方法模式
      • 迭代器模式
      • 策略模式
      • 解释器模式
      • 观察者模式
      • 备忘录模式
      • 命令模式
      • 中介者模式
      • 责任链模式
      • 访问者模式
      • 状态模式
  • Java
    • Java Core
      • JVM 如何加载类
      • JVM 垃圾回收
      • JVM G1GC
      • JVM G1GC Q&A
      • JVM 与 Hbase
      • JVM ZGC Overview
      • JVM ZGC 内存管理
      • JVM ZGC 线程
      • JVM ZGC 垃圾回收
      • JVM ZGC 日志分析
      • JVM ZGC 参数调优
    • checkstyle
  • Golang
    • 源码阅读
      • Goroutines
      • Channel
    • gRPC
      • 1、快速开始
      • 2、什么是gRPC
      • 3、gRPC概念梳理
      • 4、基于Golang的gRPC入门
      • 5、gRPC组件ProtocolBuffers介绍
      • 6、gRPC组件Http 2.0
      • 7、错误处理和Debug
      • 8、gRPC身份验证
      • 9、服务注册与发现
      • 10、gRPC与gRPC Gateway
      • 11、gRPC与分布式链路追踪
  • Scala
    • 数据结构与算法
      • 数组
      • 队列
    • 函数式编程
      • 高阶函数
      • 偏函数
    • Immutable Collection
      • List
    • Mutable Collection
      • Array
    • 常见函数操作
      • A
        • aggregate
        • andThen
        • appended
        • appendedAll
      • C
        • chain
        • collect
        • collectFirst
        • combinations
        • compose
        • concat
        • cond
        • condOpt
        • const
        • contains
        • containsSlice
        • copyToArray
        • corresponds
        • count
        • curried
      • D
        • diff
        • distinct
        • distinctBy
        • drop
        • dropRight
        • dropWhile
      • E
        • empty(PartialFunction)
        • empty(collections)
        • endsWith
        • exists
      • F
        • fill
        • filter
        • filterKeys
        • filterNot
        • find
        • findLast
        • flatMap
        • flatten
        • fold
        • foldLeft
        • foldRight
        • forall
        • foreach
        • fromFunction
      • G
        • getOrElse (Map)
        • getOrElse (Option)
        • groupBy
        • groupMap
        • groupMapReduce
        • grouped
      • H
        • head
        • headOption
      • I
        • indexOf
        • indexOfSlice
        • indexWhere
        • indices
        • init
        • inits
        • intersect
        • isDefinedAt (Map)
        • isDefinedAt (Seq)
        • isEmpty
        • isTraversableAgain
      • K
        • keys
      • L
        • last
        • lastIndexOf
        • lastIndexOfSlice
        • lastIndexWhere
        • lastOption
        • length
        • lift
      • M
        • map
        • mapConserve
        • mapValues
        • max
        • maxBy
        • maxByOption
        • maxOption
        • min
        • minBy
        • minByOption
        • minOption
        • mkString
      • N
        • nonEmpty
      • O
        • orElse
      • P
        • padTo
        • par
        • partition
        • partitionMap
        • patch
        • permutations
        • prefixLength
        • prepended
        • prependedAll
        • product
      • R
        • range
        • reduce
        • reduceLeft
        • reduceLeftOption
        • reduceOption
        • reduceRight
        • reduceRightOption
        • reverse
        • reverseIterator
        • reverseMap
        • runWith
      • S
        • sameElements
        • scan
        • scanLeft
        • scanRight
        • search
        • segmentLength
        • size
        • slice
        • sliding
        • sortBy
        • sortWith
        • sorted
        • span
        • splitAt
        • startsWith
        • sum
      • T
        • tabulate
        • tail
        • tails
        • take
        • takeRight
        • takeWhile
        • transpose
        • tupled
      • U
        • unfold
        • union
        • unlift
        • untupled
        • unzip
        • unzip3
        • updated
      • V
        • values
        • view
      • W
        • withFilter
        • withDefault
        • withDefaultValue
      • Z
        • zip
        • zipAll
        • zipWithIndex
      • map
      • flatmap
      • filter
      • reduceLeft
      • foldLeft
    • Futures
      • Method with future as return type
      • Non blocking future result
      • Chain futures using flatMap
      • Chain futures using for comprehension
      • Future Option with for comprehension
      • Future Option with map
      • Composing Futures
      • Future Sequence
      • Future Traverse
      • Future foldLeft
      • Future reduceLeft
      • Future firstCompletedOf
      • Future zip
      • Future zipWith
      • Future andThen
      • Future configure threadpool
      • Future recover
      • Future recoverWith
      • Future fallbackTo
      • Future promise
    • Akka
  • Algorithm
  • Docker
  • Kubernetes
    • 二进制安装kubernetes
      • 00.从零开始
  • Architecture
    • Infrastructure
      • Opentracing
      • Jaeger && ZipKin
      • SkyWalking
      • Consul
      • Envoy
      • Service Mesh
      • Service Mesh: Istio 详解
      • Service Mesh: 基于 Istio 的落地实践(一)
    • CAS
      • CAS Server
      • CAS Service Management
      • CAS 集成LDAP
      • CAS 集成gitlab
      • CAS SSO & SLO
      • CAS Gitbook
    • xCAT
  • Netty
  • DDD
  • Reactive Programming
    • Reactor
      • Publisher
      • Subscriber
      • Subscription
      • Processor
    • WebFlux
  • Gitlab
    • Git Hook
  • CICD
    • Jenkins
      • Kubectl
Powered by GitBook
On this page
  • 为单个Git Repo 创建server hook
  • 为所有的 Git Repo 创建server hook
  • Gitlab基于git-hooks做checkstyle代码检测

Was this helpful?

  1. Gitlab

Git Hook

PreviousGitlabNextCICD

Last updated 3 years ago

Was this helpful?

Git 支持在不同操作上执行的Hook。这些Hook在服务器上运行,可用于根据存储库的状态强制执行特定的提交策略或执行其他任务。

Git 支持下面的Hook:

  • pre-receive

  • post-receive

  • update

Server-side Git hooks 可以被配置到 某一个Repo或者全部的Repo上。

三种类型的hook 有什么区别 ,可以通过 ,进行参考。

为单个Git Repo 创建server hook

对于不同的安装类型,Repo 位置可能不一样。

  • 从源码安装,路径可能是 /home/git/repositories/<group>/<project>.git.

  • 通过官方库安装,路径一般是/var/opt/gitlab/git-data/repositories/<group>/<project>.git。

按照下面的步骤为某一个Repo添加Server-Side Hook。

  1. Admin area > Projects 选择对应的project

  2. 找到 如下图所示的位置。 参考 ,根据projec id 找到服务器上的存储地址。

    实际上,efile 的存储地址就是 /var/opt/gitlab/git-data/repositories/@hashed/78/5f/785f3ec7eb32f30b90cd0fcf3657d388b5ff4297f2f9716ff66e9b69c05ddd09.git

  3. 在 存储目录下,创建一个新的目录 custom_hooks.

  4. 在custom_hooks 目录下,创建一个与 hook 类型一致的文件。例如一个 pre-receive 类型的文件就是 pre-receive,并且没有后缀。

  5. 对pre-receive文件,添加可执行权限,并且确保被 Git User 拥有。

  6. 在 pre-receive 编写对应的脚本就可以了。

为所有的 Git Repo 创建server hook

默认的全局 server hook 目录是 GitLab Shell directory (gitlab-shell/hooks). 被添加到这里的任何一个Server Hook 适用于 所有的repositories, 包括:

  • Project and group wiki repositories, 这类存储库的名字格式一般 是 <id>.wiki.git.

  • 某个项目下的 Design management repositories,这类存储库的名字格式一般是 <id>.design.git .

默认的路径,在不同的安装策略下可能不同:

  • 源码 安装一般是 /home/git/gitlab-shell/hooks。

  • 通过官方库安装,/opt/gitlab/embedded/service/gitlab-shell/hooks.

按照下面的步骤,就可以设置全局的 Server Hook。

  1. 切换到对应的 Gitlab Shell 目录下。

  2. 在这个路径下,根据Hook 的类型创建新的目录,例如 pre-receive.d, post-receive.d, or update.d。

  3. 在每个路径下,添加对应的脚本,并赋予相应的执行权限,就可以了。

Gitlab基于git-hooks做checkstyle代码检测

转载自

https://my.oschina.net/leelance/blog/1922709
https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks
Translate hashed storage paths
releative path