Introducing public builds for AWS CodeBuild
Using , you can now share both the logs and the artifacts produced by CodeBuild projects. This blog post explains how to configure an existing CodeBuild project to enable public builds.
AWS CodeBuild is a fully managed continuous integration service that compiles source code, runs tests, and produces software packages that are ready to deploy. With CodeBuild, you don’t need to provision, manage, and scale your own build servers. With this new feature, you can now make the results of a CodeBuild project build publicly viewable. Public builds simplify the collaboration workflow for open source projects by allowing contributors to see the results of Continuous Integration (CI) tasks.
How public builds work
During a project build, CodeBuild will place build logs in either (Amazon S3) or , depending on how the customer has configured the project’s LogsConfig property. Optionally, a project build can produce artifacts that persist after the build has completed. During a project build that has public builds enabled, CodeBuild will set an environment variable named CODEBUILD_PUBLIC_BUILD_URL that supplies the URL for that build’s publicly viewable logs and artifacts. When a user navigates to that URL, CodeBuild will use an , you can provision CodeBuild projects using infrastructure as code (IaC). To update an existing CodeBuild project to enable public builds add the following two fields to your project definition:
[/code]
CodeBuildProject:
Type: AWS::CodeBuild::Project
Properties:
ServiceRole: !GetAtt CodeBuildRole.Arn
LogsConfig:
CloudWatchLogs:
GroupName: !Ref LogGroupName
Status: ENABLED
StreamName: ServerlessRust
Artifacts:
Type: S3
Location: !Ref ArtifactBucket
Name: ServerlessRust
NamespaceType: BUILD_ID
Packaging: ZIP
Environment:
Type: LINUX_CONTAINER
ComputeType: BUILD_GENERAL1_LARGE
Image: aws/codebuild/standard:4.0
PrivilegedMode: true
Triggers:
BuildType: BUILD
Webhook: true
FilterGroups:
- - Type: EVENT
Pattern: PULL_REQUEST_CREATED,PULL_REQUEST_UPDATED
Source:
Type: GITHUB
Location: "https://github.com/richardhboyd/ServerlessRust.git"
BuildSpec: |
version: 0.2
phases:
build:
commands:
- sam build
artifacts:
files:
- .aws-sam/build/**/*
discard-paths: no
Visibility: PUBLIC_READ
ResourceAccessRole: !Ref PublicReadRole # Note that this references the role defined in the previous section.[/code]
[/code]
Disabling public builds
If a project has public builds enabled and you would like to disable it, you can clear the check-box named Enable public build access in the project configuration or set the Visibility to PRIVATE in the CloudFormation definition for the project. To prevent any project in your AWS account from using public builds, you can set an service control policy (SCP) to deny the IAM Action CodeBuild:UpdateProjectVisibility
Conclusion
With CodeBuild public builds, you can now share build information for your open source projects with all contributors without having to grant them direct access to your AWS account. This post explains how to enable public builds with AWS CodeBuild using both the console and CloudFormation, create a least-privilege IAM role for sharing the public build results, and how to disable public builds for a project.

