0

configure Cloud Build to build and test Node.js but am getting error.

code snippet of cloudbuild.yml file

steps:
    - id: 'APP INSTAL NPM'
      name: node:$_NODE_VERSION
      entrypoint: npm
      args: ['install', '--prefix ./ui']
    - id: 'APP BUILD PROCESS WITH NODE NPM'
      name: node:$_NODE_VERSION
      entrypoint: npm
      args: ['run', 'build', '--prefix ./ui']
timeout: 6000s # 20 minute

git reop inside ui directory i have a application so adding --prefix still getting this error

Step #1 - "APP BUILD PROCESS WITH NODE NPM": npm ERR! code ENOENT

Step #1 - "APP BUILD PROCESS WITH NODE NPM": npm ERR! syscall open

Step #1 - "APP BUILD PROCESS WITH NODE NPM": npm ERR! path /workspace/package.json

Step #1 - "APP BUILD PROCESS WITH NODE NPM": npm ERR! errno -2

Step #1 - "APP BUILD PROCESS WITH NODE NPM": npm ERR! enoent ENOENT: no such file or directory, open '/workspace/package.json'

Step #1 - "APP BUILD PROCESS WITH NODE NPM": npm ERR! enoent This is related to npm not being able to find a file.

Arun
  • 142
  • 1
  • 1
  • 9
  • You can check out the threads having similar errors that you are facing: [Thread1](https://stackoverflow.com/questions/49415958/what-could-cause-an-error-related-to-npm-not-being-able-to-find-a-file-no-conte), [Thread2](https://stackoverflow.com/questions/49651221/npm-enoent-no-such-file-or-directory-rename) – Akshansha Singhal Nov 17 '21 at 13:45

1 Answers1

0

For those who are encountering this problem, GCP cloud-build has a dir field to set the working directory. This snippet should work:

steps:
- id: 'APP INSTAL NPM'
  name: node:$_NODE_VERSION
  dir: 'ui'
  entrypoint: npm
  args: ['install']
- id: 'APP BUILD PROCESS WITH NODE NPM'
  name: node:$_NODE_VERSION
  dir: 'ui'
  entrypoint: npm
  args: ['run', 'build']