有什么方法可以在 cloudbuild.yaml 中运行 npm install 和 npm run build 吗?

问题描述 投票:0回答:2

我有这个反应应用程序,我需要通过谷歌云构建部署到谷歌云存储中,我试图添加一个cloudbuild.yaml并添加一些步骤来运行npm

这就是我所拥有的:

steps:
  - name: bash
    script: |
      npm install --force
  - name: bash
    script: |
      npm run build
  - name: "gcr.io/google.com/cloudsdktool/cloud-sdk"
    entrypoint: gcloud
    args:
      ["storage", "cp", "/dist/*", "gs://bucket"]
timeout: 1200s
options:
  logging: CLOUD_LOGGING_ONLY

但是云构建向我显示错误:

Step #0: script: line 2: npm: not found
yaml google-cloud-build cloudbuild.yaml
2个回答
2
投票

如本文档中所述。在构建应用程序之前,您必须确保项目的所有依赖项都是从 npm 或 YARN 安装的。

steps:
- name: node
  entrypoint: npm
  args: ['install']

如果您在 package.json 中定义了测试脚本,则可以通过将 test 添加到 args 字段来配置 Cloud Build 来运行该脚本:

steps:
- name: node
  entrypoint: npm
  args: ['install']
- name: node
  entrypoint: npm
  args: ['test']

您还可以查看此链接和github线程


2
投票

在您的步骤中,您使用

name: bash
,因此您使用安装了 bash 的容器,而不是 NPM。

例如使用容器名称“node:19”来获取符合node/npm标准的容器并能够调用NPM。

© www.soinside.com 2019 - 2024. All rights reserved.