Example of buildspec.yaml
Basic Information - Needs to be on the root directory - versions: - 0.
Table of Contents
Get Yours Today
Discover our wide range of products designed for IT professionals. From stylish t-shirts to cutting-edge tech gadgets, we've got you covered.
Basic Information
- Needs to be on the root directory
- versions:
- 0.1 -> runs each build in separate instance
- 0.2 -> run each build in the same instance
- run-as: You can mention the user name of the linux operating system
- env:
- one or more environment variables
- you can use parameter-store or secrets-manager variables
- proxy: If you want to run your build in the explicit proxy server
- batch:
- phases: the commands runs during each phase, it's similar to the stages in the Jenkins
- install: for installing packages in the build dev
- pre_build: commands to run before building
- build: commands to run during build
- post_build: commands to run after build
- reports: Where you want to send the reports
- artifacts: Where you can find the build output
Sub-Sequences of phases:
all of the phases have sub sequences
run-as: Linux-user-name
on-failure: ABORT | CONTINUE
runtime-versions:
runtime: version
runtime: version
commands:
- command
- command
finally:
- command
- command
List of all available runtimes for codebuild
Examples:
Example 01:
version: 0.2
phases:
install:
commands:
- echo Entered the install phase...
finally:
- echo This always runs even if the update or install command fails
- go version
pre_build:
commands:
- echo Entered the pre_build phase...
finally:
- echo This always runs even if the login command fails
build:
commands:
- echo Entered the build phase...
- echo Build started on `date`
finally:
- echo This always runs even if the install command fails
post_build:
commands:
- echo Entered the post_build phase...
- echo Build completed on `date`
Example 02:
This is an example of an artifact name appended with the date the artifact is created.
version: 0.2
phases:
install:
runtime-versions:
java: corretto11
pre_build:
commands:
- echo Nothing to do in the pre_build phase...
build:
commands:
- echo Build started on `date`
- mvn install
post_build:
commands:
- echo Build completed on `date`
artifacts:
files:
- target/messageUtil-1.0.jar
Example 03:
version: 0.2
phases:
install:
commands:
- npm install
build:
commands:
- npm test
artifacts:
files:
- '**/*'
Example 04:
This is an example of an artifact name that uses a CodeBuild environment variable. For more information, see Environment variables in build environments.
version: 0.2
phases:
build:
commands:
- rspec HelloWorld_spec.rb
artifacts:
files:
- '**/*'
name: myname-$AWS_REGION
Example 05:
version: 0.2
env:
variables:
IMAGE_REPO_NAME: "node-calculator-build-environment"
IMAGE_TAG: "latest"
phases:
pre_build:
commands:
- $(aws ecr get-login --region $AWS_DEFAULT_REGION)
build:
commands:
- docker build -f Dockerfile.build_env -t $IMAGE_REPO_NAME:latest .
- docker tag $IMAGE_REPO_NAME:$IMAGE_TAG $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME:$IMAGE_TAG
- docker push $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME:$IMAGE_TAG
...