-
-
Save jl91/2daa4c2efaedee2e6da405c618e62f0e to your computer and use it in GitHub Desktop.
example of artifacts being shared between AWS CodeBuild projects
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AWSTemplateFormatVersion: 2010-09-09 | |
Description: > | |
complete example of artifacts being shared between AWS CodeBuild projects | |
and AWS CodePipeline stages. | |
Resources: | |
CodePipelineRole: | |
Type: AWS::IAM::Role | |
Properties: | |
AssumeRolePolicyDocument: | |
Version: "2012-10-17" | |
Statement: | |
Effect: Allow | |
Principal: | |
Service: codepipeline.amazonaws.com | |
Action: sts:AssumeRole | |
Path: / | |
ManagedPolicyArns: | |
- arn:aws:iam::aws:policy/AdministratorAccess | |
CodeBuildRole: | |
Type: AWS::IAM::Role | |
Properties: | |
AssumeRolePolicyDocument: | |
Version: "2012-10-17" | |
Statement: | |
Effect: Allow | |
Principal: | |
Service: codebuild.amazonaws.com | |
Action: sts:AssumeRole | |
ManagedPolicyArns: | |
- arn:aws:iam::aws:policy/AdministratorAccess | |
ArtifactStoreBucket: | |
Type: AWS::S3::Bucket | |
Properties: | |
VersioningConfiguration: | |
Status: Enabled | |
AccessControl: BucketOwnerFullControl | |
CodeCommitRepo1: | |
Type: AWS::CodeCommit::Repository | |
Properties: | |
RepositoryName: !Sub '${AWS::StackName}-repo-one' | |
RepositoryDescription: CodeCommit Repository | |
CodeCommitRepo2: | |
Type: AWS::CodeCommit::Repository | |
Properties: | |
RepositoryName: !Sub '${AWS::StackName}-repo-two' | |
RepositoryDescription: CodeCommit Repository | |
CodeBuildProjectOne: | |
Type: AWS::CodeBuild::Project | |
DependsOn: CodeBuildRole | |
Properties: | |
Artifacts: | |
Type: CODEPIPELINE | |
Environment: | |
ComputeType: BUILD_GENERAL1_SMALL | |
Image: aws/codebuild/amazonlinux2-x86_64-standard:3.0 | |
Type: LINUX_CONTAINER | |
Name: !Sub ${AWS::StackName}CodeBuildProjectOne | |
ServiceRole: !Ref CodeBuildRole | |
Source: | |
Type: CODEPIPELINE | |
BuildSpec: !Sub | | |
version: 0.2 | |
phases: | |
build: | |
commands: | |
- env | grep CODEBUILD | |
- ls -laR | |
post_build: | |
commands: | |
# transformations here | |
- mkdir /many-to-one | |
- cd $CODEBUILD_SRC_DIR | |
- cp -R ./* /many-to-one | |
- cd $CODEBUILD_SRC_DIR_Source2Artifact | |
- cp -R ./* /many-to-one | |
artifacts: | |
files: | |
- '**/*' | |
base-directory: '/many-to-one' | |
CodeBuildProjectTwo: | |
Type: AWS::CodeBuild::Project | |
DependsOn: CodeBuildRole | |
Properties: | |
Artifacts: | |
Type: CODEPIPELINE | |
Environment: | |
ComputeType: BUILD_GENERAL1_SMALL | |
Image: aws/codebuild/amazonlinux2-x86_64-standard:3.0 | |
Type: LINUX_CONTAINER | |
Name: !Sub ${AWS::StackName}CodeBuildProjectTwo | |
ServiceRole: !Ref CodeBuildRole | |
Source: | |
Type: CODEPIPELINE | |
BuildSpec: !Sub | | |
version: 0.2 | |
phases: | |
build: | |
commands: | |
- env | grep CODEBUILD | |
- ls -laR | |
- touch baz | |
artifacts: | |
files: | |
- '**/*' | |
secondary-artifacts: | |
BuildTwoFoo: | |
files: | |
- './foo' | |
BuildTwoBar: | |
files: | |
- './bar' | |
BuildTwoBaz: | |
files: | |
- './baz' | |
CodeBuildProjectThree: | |
Type: AWS::CodeBuild::Project | |
DependsOn: CodeBuildRole | |
Properties: | |
Artifacts: | |
Type: CODEPIPELINE | |
Environment: | |
ComputeType: BUILD_GENERAL1_SMALL | |
Image: aws/codebuild/amazonlinux2-x86_64-standard:3.0 | |
Type: LINUX_CONTAINER | |
Name: !Sub ${AWS::StackName}CodeBuildProjectThree | |
ServiceRole: !Ref CodeBuildRole | |
Source: | |
Type: CODEPIPELINE | |
BuildSpec: !Sub | | |
version: 0.2 | |
phases: | |
build: | |
commands: | |
- env | grep CODEBUILD | |
- ls -laR | |
post_build: | |
commands: | |
# transformations here | |
- mkdir -p /many-to-many/first | |
- mkdir -p /many-to-many/second | |
- cd $CODEBUILD_SRC_DIR | |
- cp foo /many-to-many/first | |
- cd $CODEBUILD_SRC_DIR_BuildTwoBar | |
- cp bar /many-to-many/first | |
- cp bar /many-to-many/second | |
- cd $CODEBUILD_SRC_DIR_BuildTwoBaz | |
- cp baz /many-to-many/second | |
artifacts: | |
files: | |
- '**/*' | |
secondary-artifacts: | |
BuildThreeFirst: | |
files: | |
- '**/*' | |
base-directory: '/many-to-many/first' | |
BuildThreeSecond: | |
files: | |
- '**/*' | |
base-directory: '/many-to-many/second' | |
CodePipeline: | |
Type: AWS::CodePipeline::Pipeline | |
Properties: | |
RoleArn: !GetAtt CodePipelineRole.Arn | |
ArtifactStore: | |
Location: | |
Ref: | |
ArtifactStoreBucket | |
Type: S3 | |
Stages: | |
- Name: Source | |
Actions: | |
- InputArtifacts: [] | |
Name: Source1 | |
ActionTypeId: | |
Category: Source | |
Owner: AWS | |
Version: 1 | |
Provider: CodeCommit | |
OutputArtifacts: | |
- Name: Source1Artifact | |
Configuration: | |
BranchName: main | |
RepositoryName: !Sub '${AWS::StackName}-repo-one' | |
RunOrder: 1 | |
- InputArtifacts: [] | |
Name: Source2 | |
ActionTypeId: | |
Category: Source | |
Owner: AWS | |
Version: 1 | |
Provider: CodeCommit | |
OutputArtifacts: | |
- Name: Source2Artifact | |
Configuration: | |
BranchName: main | |
RepositoryName: !Sub '${AWS::StackName}-repo-two' | |
RunOrder: 1 | |
- Name: Build | |
Actions: | |
- Name: BuildOne | |
ActionTypeId: | |
Category: Build | |
Owner: AWS | |
Version: 1 | |
Provider: CodeBuild | |
OutputArtifacts: | |
- Name: BuildOne | |
InputArtifacts: | |
- Name: Source1Artifact | |
- Name: Source2Artifact | |
Configuration: | |
ProjectName: !Ref CodeBuildProjectOne | |
PrimarySource: Source1Artifact | |
RunOrder: 1 | |
- Name: BuildTwo | |
ActionTypeId: | |
Category: Build | |
Owner: AWS | |
Version: 1 | |
Provider: CodeBuild | |
OutputArtifacts: | |
- Name: BuildTwoFoo | |
- Name: BuildTwoBar | |
- Name: BuildTwoBaz | |
InputArtifacts: | |
- Name: BuildOne | |
Configuration: | |
ProjectName: !Ref CodeBuildProjectTwo | |
RunOrder: 2 | |
- Name: BuildThree | |
ActionTypeId: | |
Category: Build | |
Owner: AWS | |
Version: 1 | |
Provider: CodeBuild | |
OutputArtifacts: | |
- Name: BuildThreeFirst | |
- Name: BuildThreeSecond | |
InputArtifacts: | |
- Name: BuildTwoFoo | |
- Name: BuildTwoBar | |
- Name: BuildTwoBaz | |
Configuration: | |
ProjectName: !Ref CodeBuildProjectThree | |
PrimarySource: BuildTwoFoo | |
RunOrder: 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment