首页 > 解决方案 > 通过 Google Cloud 构建触发器部署“sh: 1: jest: Permission denied”

问题描述

我正在谷歌云平台上部署一个 nodejs 应用程序。

我的 cloudbuild.yaml 看起来像这样:

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"]

我设置了所有 API 并启用它们(App 引擎等)并通过以下命令进行部署:

gcloud builds submit --config cloudbuild.yaml .

部署成功并且步骤是否通过(通过 Jest 进行的测试)。

但是,当通过Bitbucket存储库触发部署时,我在步骤 1(测试步骤)中收到此错误:

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

因此通过 gcloud SDK 部署成功,但通过触发器返回错误。

请提供任何帮助

编辑 我创建了一个 Github repo 并重复了相同的步骤,触发器中出现了相同的错误:

已经有图片(带摘要):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

标签: node.jsgoogle-app-enginegoogle-cloud-platformcontinuous-integrationjestjs

解决方案


固定

我将 package.json 中的测试脚本更改为:

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

至:

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

推荐阅读