返回文章列表
AWS-CodeBuild
工具
【前言】
aws code build用来构建代码
【创建项目】
地址
https://us-west-2.console.aws.amazon.com/codesuite/codebuild/start?region=us-west-2
填写名称
点击右边的创建项目按钮,填写项目名称

选择构建来源
这里选code commit,然后选择对应的仓库和分支

选择环境
本文是前端项目,选择了有nodejs18对应的ec2环境
对应环境的runtime关系可以看这里, https://docs.aws.amazon.com/codebuild/latest/userguide/available-runtimes.html
不同环境的价格,详见: https://aws.amazon.com/cn/codebuild/pricing/
比如需要nodejs 18版本,只能选对应的几种环境,
但是lambda在使用过程中npm i报错,后面使用ec2后成功,

设置构建脚本
可以用yaml文件,也可以在线写
build脚本的规范,详见: https://docs.aws.amazon.com/zh_cn/codebuild/latest/userguide/build-spec-ref.html
version: 0.2
#env:
#variables:
# key: "value"
# key: "value"
#parameter-store:
# key: "value"
# key: "value"
#secrets-manager:
# key: secret-id:json-key:version-stage:version-id
# key: secret-id:json-key:version-stage:version-id
#exported-variables:
# - variable
# - variable
#git-credential-helper: yes
#batch:
#fast-fail: true
#build-list:
#build-matrix:
#build-graph:
phases:
install:
runtime-versions:
nodejs: 18
commands:
pre_build:
commands:
- npm i
- npx nx reset
build:
commands:
- npm run release:online
#post_build:
#commands:
# - command
# - command
#reports:
#report-name-or-arn:
#files:
# - location
# - location
#base-directory: location
#discard-paths: yes
#file-format: JunitXml | CucumberJson
artifacts:
files:
- packages/_server/**/*
name: server-$CODEBUILD_BUILD_ID-$(date +%Y-%m-%d)
#cache:
#paths:
# - paths
选择构件存储位置
这里是aws s3,创建教程: https://blog.insistime.com/aws-s3
构件打包为zip自动传到s3对应的位置

日志,一般选择cloud watch,如下

至此,一个aws code build项目创建成功
【开始构建】
创建好后,点击开始构建就会进行构建的过程

点击后可以看到对应的构建过程的日志