Skip to content

Instantly share code, notes, and snippets.

@rupertbg
Last active October 7, 2023 10:29
Show Gist options
  • Save rupertbg/78f8eca2cee34b78c64b8c7e9528af37 to your computer and use it in GitHub Desktop.
Save rupertbg/78f8eca2cee34b78c64b8c7e9528af37 to your computer and use it in GitHub Desktop.
Use the buildspec.yml from another (Secondary Source) repo for your Source repo in AWS CodeBuild (Demonstrated with Cloudformation)
CodeBuildProject:
Type: AWS::CodeBuild::Project
Properties:
Name: !Ref GitHubRepoName
BadgeEnabled: true
Description: Builds a Docker image using a BuildSpec from another repo
ServiceRole: !ImportValue Your-CodeBuild-Role
TimeoutInMinutes: 15
Artifacts:
Type: NO_ARTIFACTS
Source:
SourceIdentifier: my-repo
Type: GitHub
Location: !Sub https://github.com/${GitHubRepoOwner}/${GitHubRepoName}.git
ReportBuildStatus: true
GitCloneDepth: 1
BuildSpec: ../the-name-of-the-buildspec-repo/buildspec.yml
SecondarySources:
- SourceIdentifier: the-buildspec-repo
Type: GitHub
Location: !Sub https://github.com/rupertbg/the-name-of-the-buildspec-repo.git
ReportBuildStatus: false
GitCloneDepth: 1
Environment:
Type: LINUX_CONTAINER
ComputeType: BUILD_GENERAL1_SMALL
Image: aws/codebuild/standard:3.0
PrivilegedMode: true
EnvironmentVariables:
- Name: CONTAINER_NAME
Value: !Ref ContainerName
- Name: ECR_REPO
Value: !Ref ECRRegistry
@Gonveliz
Copy link

Gonveliz commented Oct 6, 2023

Hi! I'm trying to use your code, but I looking the following error in the aws cli console
An error occurred (ValidationError) when calling the CreateStack operation: Template format error: At least one Resources member must be defined.

@rupertbg
Copy link
Author

rupertbg commented Oct 7, 2023

Hi! I'm trying to use your code, but I looking the following error in the aws cli console An error occurred (ValidationError) when calling the CreateStack operation: Template format error: At least one Resources member must be defined.

Hey bud, this is just a snippet of a template, a single resource you would add to a complete Cloudformation template.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment