git - 通过覆盖 "CI detected, skipping Git hooks installation"在 Jenkins 管道作业中安装 husky git hooks

标签 git jenkins continuous-integration pre-commit-hook husky

我正在尝试使用 husky安装 git hooks 作为 Jenkins 管道作业的一部分。
我已将此添加到 Jenkins 工作中:

npm install husky --save-dev
但是当作业运行时,我在 Jenkins 输出中看到了这一点:
> node-sass@4.14.1 install /home/jenkins/agent/workspace/<branch_name>/node_modules/node-sass
> node scripts/install.js

Downloading binary from https://github.com/sass/node-sass/releases/download/v4.14.1/linux_musl-x64-72_binding.node
Download complete
Binary saved to /home/jenkins/agent/workspace/<branch_name>/node_modules/node-sass/vendor/linux_musl-x64-72/binding.node
Caching binary to /root/.npm/node-sass/4.14.1/linux_musl-x64-72_binding.node

> husky@4.3.0 install /home/jenkins/agent/workspace/<branch_name>/node_modules/husky
> node husky install

husky > Setting up git hooks
CI detected, skipping Git hooks installation.
husky > Done
... 和 .git/hooks/precommit钩子(Hook)文件永远不会被创建。
故障排除研究笔记:
  • husky v4 documentation它说“默认情况下,Husky 不会安装在 CI 服务器上。”我找不到有关如何覆盖该默认行为的任何文档。
  • searching the repo code 时,我什至在代码中找不到“检测到 CI,跳过 Git 钩子(Hook)安装”字符串.
  • 我找到了一个 issue在 2017 年的 husky repo 中,开发人员解释了为什么 husky 没有安装在 CI 中,但没有解释如何覆盖它,而是表示他们有兴趣了解在 CI 中运行 husky 的用例(暗示至少在2017 没有办法覆盖)。
  • 在此 blog post从 2019 年 6 月起,作者暗示 husky 根本无法在 CI 中运行并且它使用 is-ci检测它是否在 CI 服务器上运行。 is-ci赫斯基文档中提到了here他们建议使用它来检测 husky 是否在 CI 中运行并使用 HUSKY=0禁用它。但是,我遇到的行为是 husky 已经没有在 CI 中运行。我试过设置 HUSKY=1在 Jenkins 的工作中,但这没有效果。
  • 最佳答案

    对于路人来说,这个问题仍然与 husky 4+ 相关。在 CI 系统中,您可以运行:

    export HUSKY_SKIP_INSTALL=1
    
    例如:
    docker
    ENV HUSKY_SKIP_INSTALL=1
    
    亚搏体育app CI
    build:
      script:
        - export HUSKY_SKIP_INSTALL=1
        - npm install
    
    GitHub 工作流
    jobs:
      build:
        steps:
          env:
            HUSKY_SKIP_INSTALL: 1
    
    Jenkins
    Create a global property .

    关于git - 通过覆盖 "CI detected, skipping Git hooks installation"在 Jenkins 管道作业中安装 husky git hooks,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64724492/

    相关文章:

    针对存储的 Git diff

    git - git 中的硬 merge

    jenkins - 如何禁用显示 "New version of Jenkins (2.62) is available for download (changelog)"?

    Dockerfile - 入口点不保存变量

    Android SDK 下载作为 Gradle 构建的一部分

    持续集成中的数据库变更管理

    IOS/Xcode/Git : Suddenly can't commit changes withunable to auto-detect email address error

    Android Studio 在执行 git merge 时卡住

    jenkins - 绕过代码中的脚本安全插件

    git - 如何在 Jenkins 中构建最新的 git flow 发布分支?