1
votes

AWS have recently (20/12/19) released support for shared CodeBuild Report Groups in CloudFormation

I'd like to use a ReportGroup in my CloudFormation, but can't see how I'm supposed to configure CodeBuild to use it.

It looks like reporting configuration is done in the buildspec. I can see an example of a hardcoded reference to a report group in this example buildspec snippet:

reports:
  arn:aws:codebuild:your-region:your-aws-account-id:report-group/report-group-name-1: #surefire junit reports
    files:
      - '**/*'
    base-directory: 'surefire/target/surefire-reports'
    discard-paths: false

Obviously, if I'm creating my ReportGroup via CloudFormation, I don't know the ARN to put into the buildspec.

So, my question is how can I inject a dynamically created report group ARN into the buildspec? Or is there a different/better way of configuring CodeBuild to use a ReportGroup created by CloudFormation?

1

1 Answers

4
votes

If it is all being created by CloudFormation then you could add the buildspec.yaml creation to the template and add the ARN via the intrinsic function Fn::Sub or !Sub

  CodeBuildProject:
    Type: "AWS::CodeBuild::Project"
    Properties:
      Source:
        BuildSpec: !Sub |
          version: 0.2
          env:
            variables:
              key: "value"
              key: "value"
          phases:
            install:
              runtime-versions:
                runtime: version
              commands:
                - command
            pre_build:
              commands:
                - command
            build:
              commands:
                - command
            post_build:
              commands:
                - command
          reports:
            arn:aws:codebuild:${AWS::Region}:${AWS::AccontID}:report-group/${ReportGroupName}:
              files:
                - location
              base-directory: location
              discard-paths: yes
              file-format: JunitXml | CucumberJson

Take note of the !Sub after BuildSpec.

Where ReportGroupName is equal to the name property value given in AWS::CodeBuild::ReportGroup