- AWS Automation Cookbook
- Nikit Swaraj
- 367字
- 2021-07-02 23:00:44
Syntax
Build specs must be expressed in the YAML format:
version: 0.2
env:
variables:
key: "value"
key: "value"
phases:
install:
commands:
- command
- command
pre_build:
commands:
- command
- command
build:
commands:
- command
- command
post_build:
commands:
- command
- command
artifacts:
files:
- location
- location
discard-paths: yes
base-directory: location
Now, let's see what each term means to CodeBuild.
- version: This represents the build spec version. AWS recommends the usage of 0.2.
- env : This represents the information of custom variables that we can assign.
- variables: This represents the mapping of key and value, where it represents a custom environment variable, for example:
env:
variables:
JAVA_HOME: "/opt/java-7-openjdk-amd64"
- phases: It contains commands that AWS CodeBuild will run during each phase of the build.
- install: This represents the commands that AWS CodeBuild will run during installation. It is recommended to use the install phase only for installing packages in the build environment, for example:
phases:
install:
commands:
- apt-get update -y
- apt-get install -y maven
-
- pre_build: This represents the commands that AWS CodeBuild will run before the build.
- build: This contains the commands that AWS CodeBuild will run during the build. For example:
build:
commands:
- echo Build started on `date`
- mvn install
-
- post_build: This contains the commands that AWS CodeBuild will run after the build. For example, you might use Maven to package the build artifacts into a JAR or WAR file.
- artifacts: This represents the information about where AWS CodeBuild can find the build output and how AWS CodeBuild will prepare it so that it can be uploaded to the Amazon S3 output bucket.
That was all about how we can write the buildspec.yml file according to our need. Now, let's write a buildspec.yml file for our NodeJS application. This time, we are using the npm tool to build the application.
Before proceeding, make sure you clone the code from GitHub (https://github.com/awsstar/CB-NodeJS-BS.git ) and create a new repository in CodeCommit and migrate the GitHub code to the newly created CodeCommit repository.
Let's take a look at the BuildSpec.yml file that we will be checking in with the application code:
version: 0.2
phases:
pre_build:
commands:
- npm install
build:
commands:
- npm run build
post_build:
commands:
- echo Build completed on `date`
artifacts:
files:
- '**/*'
推薦閱讀
- 樂高機器人EV3設(shè)計指南:創(chuàng)造者的搭建邏輯
- Dreamweaver 8中文版商業(yè)案例精粹
- RPA:流程自動化引領(lǐng)數(shù)字勞動力革命
- 精通特征工程
- AI 3.0
- JavaScript典型應用與最佳實踐
- 計算機網(wǎng)絡(luò)原理與技術(shù)
- Visual Basic.NET程序設(shè)計
- 貫通Java Web開發(fā)三劍客
- Red Hat Linux 9實務(wù)自學手冊
- Citrix? XenDesktop? 7 Cookbook
- Introduction to R for Business Intelligence
- 會聲會影X4中文版從入門到精通
- 電腦故障排除與維護終極技巧金典
- Photoshop CS4數(shù)碼照片處理入門、進階與提高