我为我的 monorepo 使用了 nx 工作区,它依赖于nx-affected实用程序来了解两种状态之间的差异。我想在将代码推送到该分支时触发暂存部署,因此我使用以下命令
yarn nx affected:build --base=origin/$CI_COMMIT_BRANCH~1 --head=$CI_COMMIT_BRANCH --prod
在本地运行它就可以了,但是在 ci 中运行它会产生以下错误
$ 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/"