

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 建立報告群組
<a name="report-group-create"></a>

 您可以使用 CodeBuild 主控台 AWS CLI、 或 buildspec 檔案來建立報告群組。您的 IAM 角色必須擁有建立報告群組所需的許可。如需詳細資訊，請參閱[測試報告許可](test-permissions.md)。

**Topics**
+ [建立報告群組 (Buildspec)](#test-report-group-create-buildspec)
+ [建立報告群組 (主控台)](#test-report-group-create-console)
+ [建立報告群組 (CLI)](#test-report-group-create-cli)
+ [建立報告群組 (CloudFormation)](#test-report-group-create-cfn)

## 建立報告群組 (Buildspec)
<a name="test-report-group-create-buildspec"></a>

使用 buildspec 建立的報告群組不會匯出原始測試結果檔案。您可以檢視報告群組，並指定匯出設定。如需詳細資訊，請參閱[更新報告群組](report-group-export-settings.md)。

**使用 buildspec 檔案建立報告群組**

1.  選擇與您 AWS 帳戶中的報告群組沒有關聯的報告群組名稱。

1.  使用此名稱設定 buildspec 檔案的 `reports` 區段。在此範例中，報告群組名稱是 `new-report-group` 並使用 JUnit 框架建立使用測試案例：

   ```
   reports:
    new-report-group: #surefire junit reports
      files:
        - '**/*'
      base-directory: 'surefire/target/surefire-reports'
   ```

   您也可以在 buildspec 中使用環境變數來指定報告群組名稱：

   ```
   version: 0.2
   env:
     variables:
       REPORT_GROUP_NAME: "new-report-group"
   phases:
     build:
       commands:
         - ...
   ...
   reports:
    $REPORT_GROUP_NAME:
      files:
        - '**/*'
      base-directory: 'surefire/target/surefire-reports'
   ```

    如需詳細資訊，請參閱[指定測試檔案](report-group-test-cases.md)及[Reports syntax in the buildspec file](build-spec-ref.md#reports-buildspec-file)。

1. 在 `commands` 區段中指定執行測試的命令。如需詳細資訊，請參閱[指定測試命令](report-group-test-case-commands.md)。

1.  執行組建。當建置完成時，便會以使用格式 `project-name-report-group-name` 的名稱建立新的報告群組。如需詳細資訊，請參閱[報告群組命名](test-report-group-naming.md)。



## 建立報告群組 (主控台)
<a name="test-report-group-create-console"></a>

使用下列程序，使用 建立報告群組 AWS 管理主控台。

**建立報告群組**

1. 在 https：//[https://console.aws.amazon.com/codesuite/codebuild/home](https://console.aws.amazon.com/codesuite/codebuild/home) 開啟 AWS CodeBuild 主控台。

1. 在導覽窗格中，選擇 **Report groups (報告群組)**。

1. 選擇 **Create report group (建立報告群組)**。

1. 在 **Report group name (報告群組名稱)** 中，輸入報告群組的名稱。

1. （選用） 對於**標籤**，輸入您希望支援服務 AWS 使用的任何標籤的名稱和值。使用 **Add row (新增資料列)** 來新增標籤。您最多可以新增 50 個標籤。

1. 如果您想要將測試報告結果的原始資料上傳至 Amazon S3 儲存貯體：

   1. 選取**匯出至 Amazon S3**。

   1. 針對 **S3 bucket name (S3 儲存貯體名稱)**，輸入 S3 儲存貯體的名稱。

   1. （選用） 對於 **S3 儲存貯體擁有者**，輸入擁有 S3 儲存貯體之帳戶的帳戶識別符。 AWS 這可讓報告資料匯出到由執行組建帳戶以外的帳戶所擁有的 Amazon S3 儲存貯體。

   1. 針對 **Path prefix (路徑前置詞)**，輸入您想要在 S3 儲存貯體中上傳測試結果的路徑。

   1. 選取 **Compress test result data in a zip file (以 zip 檔案壓縮測試結果資料)** ，以壓縮原始測試結果資料檔案。

   1. 展開 **Additional configuration (其他組態)** 以顯示加密選項。選擇下列其中一項：
      + 用於 AWS 受管金鑰 Amazon S3 **的預設 AWS 受管金鑰**。如需詳細資訊，請參閱*AWS Key Management Service 《 使用者指南*[》中的客戶受管 CMKs](https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#customer-cmk)。這是預設加密選項。
      + **選擇自訂金鑰**，以使用您建立和設定的客戶受管金鑰。針對**AWS KMS 加密金鑰**，輸入加密金鑰的 ARN。格式為 ` arn:aws:kms:<region-id>: <aws-account-id>:key/<key-id> `。如需詳細資訊，請參閱*AWS Key Management Service 《 使用者指南*》中的[建立 KMS 金鑰](https://docs.aws.amazon.com/kms/latest/developerguide/create-keys.html)。
      + **Disable artifact encryption (停用成品)** 可讓您停用加密。如果您想要共享測試結果，或發佈至靜態網站，您可以選擇此選項。(動態網站可以執行程式碼，以解密測試結果。)

      如需加密待用資料的詳細資訊，請參閱[資料加密](security-encryption.md)。
**注意**  
專案中指定的 CodeBuild 服務角色用於上傳到 S3 儲存貯體的許可。

1. 選擇 **Create report group (建立報告群組)**。

## 建立報告群組 (CLI)
<a name="test-report-group-create-cli"></a>

使用下列程序，使用 建立報告群組 AWS CLI。

**建立報告群組**

1. 建立名為 `CreateReportGroup.json` 的檔案。

1. 根據您的需求，將下列其中一個 JSON 程式碼片段複製到 `CreateReportGroup.json`：
   + 使用下列 JSON 指定您的測試報告群組將原始測試結果檔案匯出至 Amazon S3 儲存貯體。

     ```
     {
       "name": "<report-name>",
       "type": "TEST",
       "exportConfig": {
         "exportConfigType": "S3",
         "s3Destination": {
           "bucket": "<bucket-name>",
           "bucketOwner": "<bucket-owner>",
           "path": "<path>",
           "packaging": "NONE | ZIP",
           "encryptionDisabled": "false",
           "encryptionKey": "<your-key>"
         },
         "tags": [
           {
             "key": "tag-key",
             "value": "tag-value"
           }
         ]
       }
     }
     ```
     + 將 *<bucket-name>* 取代為您的 Amazon S3 儲存貯體名稱，並將 *<path>* 取代為您儲存貯體中要匯出檔案的路徑。
     + 如果您想要壓縮匯出的檔案，請為 `packaging` 指定 `ZIP`。否則請指定 `NONE`。
     + `bucketOwner` 是選用的，只有在 Amazon S3 儲存貯體為執行建置之帳戶以外的帳戶所擁有時才需要。
     + 使用 `encryptionDisabled` 指定是否要將匯出的檔案加密。如果您加密匯出的檔案，請輸入您的客戶受管金鑰。如需詳細資訊，請參閱[更新報告群組](report-group-export-settings.md)。
   + 若不要讓您的測試報告匯出原始測試檔案，請使用下列 JSON。

     ```
     {
       "name": "<report-name>",
       "type": "TEST",
       "exportConfig": {
         "exportConfigType": "NO_EXPORT"
       }
     }
     ```
**注意**  
專案中指定的 CodeBuild 服務角色用於上傳到 S3 儲存貯體的許可。

1. 執行以下命令：

   ```
   aws codebuild create-report-group --cli-input-json file://CreateReportGroupInput.json
   ```

## 建立報告群組 (CloudFormation)
<a name="test-report-group-create-cfn"></a>

使用下列指示來使用 CloudFormation 範本建立報告群組

 **使用 CloudFormation 範本建立報告群組** 

 您可以使用 CloudFormation 範本檔案來建立和佈建報告群組。如需詳細資訊，請參閱 [CloudFormation 使用者指南](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/Welcome.html)。

 下列 CloudFormation YAML 範本會建立不會匯出原始測試結果檔案的報告群組。

```
Resources:
  CodeBuildReportGroup:
    Type: AWS::CodeBuild::ReportGroup
    Properties:
      Name: my-report-group-name
      Type: TEST
      ExportConfig:
        ExportConfigType: NO_EXPORT
```

 下列 CloudFormation YAML 範本會建立報告群組，將原始測試結果檔案匯出至 Amazon S3 儲存貯體。

```
Resources:
  CodeBuildReportGroup:
    Type: AWS::CodeBuild::ReportGroup
    Properties:
      Name: my-report-group-name
      Type: TEST
      ExportConfig:
        ExportConfigType: S3
        S3Destination:
          Bucket: amzn-s3-demo-bucket
          Path: path-to-folder-for-exported-files
          Packaging: ZIP
          EncryptionKey: my-KMS-encryption-key
          EncryptionDisabled: false
```

**注意**  
專案中指定的 CodeBuild 服務角色用於上傳到 S3 儲存貯體的許可。