2
votes

I'am deploying a nodejs application in the google cloud platform.

My cloudbuild.yaml looks like this :

steps:
  - name: "gcr.io/cloud-builders/npm"
    args: ["install"]

  - name: "gcr.io/cloud-builders/npm"
    args: ["run", "test"]

  - name: "gcr.io/cloud-builders/gcloud"
    args: ["app", "deploy"]

I set up all the APIs and enabled them (App engine etc..) and deployed via the command :

gcloud builds submit --config cloudbuild.yaml .

The deployment is successful and are the steps are passed (the test via Jest).

But when the deployment is triggered via a Bitbucket repository, I get this error in the step 1 (testing step) :

Already have image (with digest): gcr.io/cloud-builders/npm

> server@1.0.0 test /workspace
> jest --detectOpenHandles

sh: 1: jest: Permission denied
npm ERR! code ELIFECYCLE
npm ERR! errno 126
npm ERR! server@1.0.0 test: `jest --detectOpenHandles`
npm ERR! Exit status 126
npm ERR! 
npm ERR! Failed at the server@1.0.0 test script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /builder/home/.npm/_logs/2020-03-13T13_42_08_361Z-debug.log

So the deployment is succeful via gcloud SDK , but returns errors via a trigger.

Any help please

EDIT I created a Github repo and repeated the same steps , the same error in the trigger :

Already have image (with digest): gcr.io/cloud-builders/npm

> server@1.0.0 test /workspace
> jest --detectOpenHandles

sh: 1: jest: Permission denied
npm ERR! code ELIFECYCLE
npm ERR! errno 126
npm ERR! server@1.0.0 test: `jest --detectOpenHandles`
npm ERR! Exit status 126
npm ERR! 
npm ERR! Failed at the server@1.0.0 test script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /builder/home/.npm/_logs/2020-03-13T14_09_58_093Z-debug.log
1

1 Answers

3
votes

Fixed:

I changed my test script in package.json from:

  "scripts": {
    "start": "node index.js",
    "test": "jest",
    "test:watch": "jest --watch"
  },

to:

  "scripts": {
    "start": "node index.js",
    "test": "sh node_modules/.bin/jest",
    "test:watch": "jest --watch"
  },