I have used nx workspaces for my monorepo which relies on the nx-affected utility to know the difference between two states. I want to trigger a staging deployment when code is pushed to that branch hence I am using the command below
yarn nx affected:build --base=origin/$CI_COMMIT_BRANCH~1 --head=$CI_COMMIT_BRANCH --prod
running this locally works just fine but running this in ci is producing the error below
$ 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
Attaching my entire ci file for reference
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/"
use before_script in gitlab-ci file to install git command
before_script:
- apk add --update git
- apk add --update nodejs npm
- npm i -g yarn