AWS CodeBuild local testing¶
Suppose you have a CodeBuild project triggered by a push on a given branch of a linked CodeCommit repo. If the build is particularly heavy, you might want to ensure its correctness before an actual commit to the related repo - for example, you might be interested in testing the build process specified in buildspec.yml
locally.
Thankfully, AWS released in 2018 the capability to do so with AWS CodeBuild agent. To use it you must:
- clone the repo with CodeBuild Docker image
- build it (~9 GB, it might take time...)
- pull of CodeBuild local agent image
- finally test a buildspec locally!
Warning 1
If you are on Windows, pay attention to EOL conversion after cloning (step 1). During build phase (step 2) you might encounter errors like this.
Warning 2
If you are on Windows, you might fail to actually test anything as reported here and here. A possible workaround consists in switching to WSL2.
Hint 1
If your build process is particularly heavy, during the test phase (step 4) it might remain stuck in Waiting for DOWNLOAD_SOURCE
step. Indeed, the default agent behaviour is to copy the source directory: you can instead mount it by using -m
option in test script, as suggested here.
Doing so, each build action which interacts with the file system will actually take place in the source directory.
Hint 2
If you want CodeBuild local agent to use a local named profile, you can execute codebuild_build.sh
with options -c -p <PROFILE_NAME>
, as suggested here.