当构建成功运行“下一次构建”时,AWS CodeBuild 不产生任何工件

AWS CodeBuild not producing any artifacts when build runs `next build` successfully

我正在使用 NextJS 并尝试CI构建和部署到 AWS Beanstalk。

这是我的buildspec.yml

version: 0.2
env:
  variables:
    NODE_ENV: "production"
phases:
  pre_build:
    commands:
      - echo Installing dependencies
      - npm install
  build:
    commands:
      - echo Building nextjs app
      - npm run build
  post_build:
    commands:
      - echo Build completed on `date`
artifacts:
  files:
    - '**/*'

我正在监视日志并且没有错误,但是 Build 阶段没有生成任何工件。因此,一旦管道移动到 Deploy 阶段。我在日志中收到此错误:

----------------------------------------
/var/log/web.stdout.log
----------------------------------------
Nov 30 01:47:31 ip-172-31-50-67 web: at /var/app/current/node_modules/next/dist/bin/next:26:341
Nov 30 01:47:31 ip-172-31-50-67 web: npm ERR! code ELIFECYCLE
Nov 30 01:47:31 ip-172-31-50-67 web: npm ERR! errno 1
Nov 30 01:47:31 ip-172-31-50-67 web: npm ERR! with-typescript@1.0.0 start: `next start`
Nov 30 01:47:31 ip-172-31-50-67 web: npm ERR! Exit status 1
Nov 30 01:47:31 ip-172-31-50-67 web: npm ERR!
Nov 30 01:47:31 ip-172-31-50-67 web: npm ERR! Failed at the with-typescript@1.0.0 start script.
Nov 30 01:47:31 ip-172-31-50-67 web: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
Nov 30 01:47:31 ip-172-31-50-67 web: npm ERR! A complete log of this run can be found in:
Nov 30 01:47:31 ip-172-31-50-67 web: npm ERR!     /home/webapp/.npm/_logs/2020-11-30T01_47_31_607Z-debug.log
Nov 30 01:47:32 ip-172-31-50-67 web: > with-typescript@1.0.0 start /var/app/current
Nov 30 01:47:32 ip-172-31-50-67 web: > next start
Nov 30 01:47:32 ip-172-31-50-67 web: Error: Could not find a valid build in the '/var/app/current/.next' directory! Try building your app with 'next build' before starting the server.
Nov 30 01:47:32 ip-172-31-50-67 web: at Server.readBuildId (/var/app/current/node_modules/next/dist/next-server/server/next-server.js:137:355)
Nov 30 01:47:32 ip-172-31-50-67 web: at new Server (/var/app/current/node_modules/next/dist/next-server/server/next-server.js:3:120)
Nov 30 01:47:32 ip-172-31-50-67 web: at createServer (/var/app/current/node_modules/next/dist/server/next.js:2:638)
Nov 30 01:47:32 ip-172-31-50-67 web: at start (/var/app/current/node_modules/next/dist/server/lib/start-server.js:1:323)
Nov 30 01:47:32 ip-172-31-50-67 web: at nextStart (/var/app/current/node_modules/next/dist/cli/next-start.js:19:125)

我不明白我还能做什么?我试过将Build阶段的Artifacts设置更改为加密和未加密,我试过无缓存LocalAmazon S3 以及缓存桶。 None 其中似乎会产生任何伪影。

谁能指出我做错了什么?

@Marcin 指出我需要仔细检查部署工件名称并确保它与构建工件输出名称相同

根据评论。

此问题是由于构建操作之后的部署操作中的 Input Artifact 设置不正确造成的。 Input Artifact 应设置为 buildartifacts,这是构建操作的输出工件。