AWS CodePipeline-Driven CodeBuild Builds: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 14: Line 14:
==Create the CodeBuild Build Project==
==Create the CodeBuild Build Project==


The CodeBuild build project can be created automatically as part of an [[AWS CloudFormation|CloudFormation]] stack, most likely the same one that creates other resources required by the CodePipeline, and the pipeline itself. A typical CloudFormation specification is:
The CodeBuild build project can be created automatically as part of an [[AWS CloudFormation|CloudFormation]] stack, most likely the same one that creates other resources required by the CodePipeline, and the pipeline itself. A typical CloudFormation specification is shown below. Aside typical configuration details such as image type and build environment size, the CloudFormation AWS::CodeBuild::Project section can be used to declare stack-specific and project-specific configuration information that will be injected as environment variables into the build container.


  Resources:
  Resources:

Revision as of 20:00, 14 March 2019

Internal

Overview

CodeBuild can be integrated with CodePipeline so CodeBuild build projects can be used at the build stage of a CodePipeline release pipeline, backing a CodePipeline build action.

Integration

The integration consists in the following steps:

Create the CodeBuild Build Project

The CodeBuild build project can be created automatically as part of an CloudFormation stack, most likely the same one that creates other resources required by the CodePipeline, and the pipeline itself. A typical CloudFormation specification is shown below. Aside typical configuration details such as image type and build environment size, the CloudFormation AWS::CodeBuild::Project section can be used to declare stack-specific and project-specific configuration information that will be injected as environment variables into the build container.

Resources:
  ...
  CodeBuildProject:
    Type: AWS::CodeBuild::Project
    Properties:
      Name: 'my-pipeline-integrated-build-project'
      Source:
        Type: CODEPIPELINE
        BuildSpec: 'buildspec.yml'
      Artifacts:
        Type: CODEPIPELINE
      Environment:
        Type: LINUX_CONTAINER
        ComputeType: BUILD_GENERAL1_SMALL
        Image: 'aws/codebuild/java:openjdk-8'
        PrivilegedMode: true
        EnvironmentVariables:
          - Name: TARGET_BUCKET
            Value:   Fn::ImportValue: !Sub '${AWS::Region}-BuildBucket'
          - Name: REPOSITORY_URI
            Value: !Sub ${AWS::AccountId}.dkr.ecr.${AWS::Region}.amazonaws.com/${ECRRepository}
          - Name: SVC_TEMPLATE
            Value: !Ref SvcTemplate
          - Name: ENV
            Value: !Ref CFEnvironment
      ServiceRole:
        Fn::ImportValue: !Sub '${AWS::Region}-CodeBuildServiceRole'
      TimeoutInMinutes: 20

The CodeBuild Project

Passing Configuration from CodePipeline to Build