/bin/sh: git: 未找到 - GitLab CI 与 Nx 工作区

/bin/sh: git: not found - GitLab CI with Nx Workspaces

我为我的 monorepo 使用了 nx 工作区,它依赖于 nx-affected 实用程序来了解两种状态之间的区别。我想在将代码推送到该分支时触发暂存部署,因此我使用下面的命令

yarn nx affected:build --base=origin/$CI_COMMIT_BRANCH~1 --head=$CI_COMMIT_BRANCH --prod

运行 这在本地工作得很好,但是 运行 这在 ci 中产生了cing 下面的错误

$ yarn nx affected:build --base=origin/$CI_COMMIT_BRANCH~1 --head=$CI_COMMIT_BRANCH --prod
yarn run v1.22.15
$ /builds/vesatogo/weave/node_modules/.bin/nx affected:build '--base=origin/staging~1' --head=staging --prod
/bin/sh: git: not found
/bin/sh: git: not found

附上我的整个 ci 文件以供参考

image: node:16-alpine
stages:
  # - install
  - build
  # - deploy
  # - test

.intall-node-yarn:
  before_script:
    - apk add --update nodejs npm
    - npm i -g yarn
cache:
  key:
    files:
      - yarn.lock
  paths:
    - node_modules
    - .yarn

# install-dependencies:
#   stage: install
#   script:
#     - yarn install --frozen-lockfile
#   rules:
#     - if: "$CI_MERGE_REQUEST_TARGET_BRANCH_NAME =~ /^development|staging|production/"
#       changes:
#         - yarn.lock

# Build production version
build:
  stage: build
  script:
    - yarn nx affected:build --base=origin/$CI_COMMIT_BRANCH~1 --head=$CI_COMMIT_BRANCH --prod
  environment:
    name: $CI_COMMIT_BRANCH
  variables:
    NEXT_PUBLIC_KITE_ENV: $NEXT_PUBLIC_KITE_ENV
  artifacts:
    paths:
      - "dist"
    expire_in: 1 day
  rules:
    - if: "$CI_COMMIT_BRANCH  =~ /^staging|production/"
# Build and push docker images
# push:
#   stage: deploy
#   image: docker:20.10.12
#   services:
#     - docker:20.10.12-dind
#   variables:
#     DOCTL_TOKEN: $DOCTL_TOKEN
#   extends:
#     - .intall-node-yarn
#   script:
#     - yarn nx run kite:dockerize
#   rules:
#     - if: "$CI_COMMIT_BRANCH  =~ /^staging|production/"

# # Deploy the application to kubernetes
# deploy:
#   stage: deploy
#   image: dtzar/helm-kubectl
#   needs:
#     - push
#   extends:
#     - .intall-node-yarn
#   script:
#     - yarn nx run kite:deploy
#   rules:
#     - if: "$CI_COMMIT_BRANCH  =~ /^staging|production/"

使用 before_script 在 gitlab-ci 文件中安装 git 命令

  before_script:
- apk add --update git
- apk add --update nodejs npm
- npm i -g yarn