

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

# 報告群組
<a name="test-report-group"></a>

*報告群組*包含測試報告並指定共用設定。您可以使用 buildspec 檔案指定要執行的測試案例，並執行其建置時要執行的命令。對於在建置專案中設定的每個報告群組，執行建置專案可以建立測試報告。多次執行使用報告群組設定的建置專案時，則會在該報告群組中建立多個測試報告，每個報告都包含針對該報告群組所指定之相同測試案例的結果。

 在建置專案的 buildspec 檔案中，會為報告群組指定測試案例。您可以在一個建置專案中最多指定五個報告群組。當您執行建置時，所有測試案例都會執行。新的測試報告會以報告群組指定的各個測試案例結果建立。每次執行新的建置時，測試案例便會執行，並以新的測試結果建立。

 報告群組可以用於多個建置專案。使用一個報告群組建立的所有測試報告都可以共用相同的組態，例如其匯出選項和許可，即使是使用不同的建置專案建立測試報告。如果測試報告是使用在多個建置專案中的一個報告群組建立，該測試報告可以包含執行多組不同的測試案例後取得的結果 (每個建置專案一組測試案例)。這是因為您可以為每個專案 buildspec 檔案中的報告群組，指定不同的測試案例檔案。您也可以編輯其 buildspec 檔案，變更建置專案中報告群組的測試案例檔案。後續建置執行時會建立新的測試報告，而且報告包含在已更新 buildspec 中的測試案例檔案結果。

**Topics**
+ [建立報告群組](report-group-create.md)
+ [報告群組命名](test-report-group-naming.md)
+ [共用報告群組](report-groups-sharing.md)
+ [指定測試檔案](report-group-test-cases.md)
+ [指定測試命令](report-group-test-case-commands.md)
+ [在 中標記報告群組 AWS CodeBuild](how-to-tag-report-group.md)
+ [更新報告群組](report-group-export-settings.md)

# 建立報告群組
<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 儲存貯體的許可。

# 報告群組命名
<a name="test-report-group-naming"></a>

 當您使用 AWS CLI 或 AWS CodeBuild 主控台建立報告群組時，您可以指定報告群組的名稱。如果您使用 buildspec 建立新的報告群組，則會使用格式 `project-name-report-group-name-specified-in-buildspec` 命名。如果報告是透過執行建置專案的建置方式建立，則此類報告皆屬於有新名稱的新報告群組。

 如果您不希望 CodeBuild 建立新的報告群組，請在組建專案的 buildspec 檔案中指定報告群組的 ARN。您可以在多個建置專案中指定報告群組的 ARN。每個建置專案執行後，報告群組包含每個建置專案建立的測試報告。

 例如，如果您以名稱 `my-report-group` 建立一個報告群組，然後在兩個名為 `my-project-1` 和 `my-project-2` 的不同建置專案中使用其名稱，並建立這兩個專案的一個建置，則會建立兩個新的報告群組。結果是採用下列名稱的三個報告群組：
+  `my-report-group`：沒有任何測試報告。
+  `my-project-1-my-report-group`：包含的報告擁有由名為 `my-project-1` 之建置專案所執行測試的結果。
+  `my-project-2-my-report-group`：包含的報告擁有由名為 `my-project-2` 之建置專案所執行測試的結果。

 如果您在這兩個專案中使用名為 `my-report-group` 之報告群組的 ARN，然後執行各個專案的建置，則仍有一個報告群組 (`my-report-group`)。該報告群組包含的測試報告含有由這兩個建置專案所執行之測試的結果。

 如果您選擇的報告群組名稱不屬於您 AWS 帳戶中的報告群組，然後將該名稱用於 buildspec 檔案中的報告群組並執行其建置專案的建置，則會建立新的報告群組。新的報告群組的名稱格式為 `project-name-new-group-name`。例如，如果 AWS 您的帳戶中沒有名為 的報告群組`new-report-group`，並在名為 的建置專案中指定報告群組`test-project`，則建置執行會以名稱 建立新的報告群組`test-project-new-report-group`。

# 共用報告群組
<a name="report-groups-sharing"></a>

報告群組共用可讓多個 AWS 帳戶或使用者檢視報告群組、其未過期的報告，以及其報告的測試結果。在此模型中，擁有報告群組的帳戶 (擁有者) 會與其他帳戶 (消費者) 共用報告群組。消費者無法編輯報告群組。報告會在建立後 30 天過期。

**Topics**
+ [共用報告群組](#report-groups-sharing-share)
+ [相關服務](#report-groups-sharing-related)
+ [存取與您共用的報告群組](report-groups-sharing-access-prereqs.md)
+ [取消共用共用報告群組](report-groups-sharing-unshare.md)
+ [識別共用報告群組](report-groups-sharing-identify.md)
+ [共用報告群組的許可](report-groups-sharing-perms.md)

## 共用報告群組
<a name="report-groups-sharing-share"></a>

 當您共用報告群組時，就會授予消費者報告群組及其報告的唯讀存取權。取用者可以使用 AWS CLI 來檢視報告群組、其報告，以及每個報告的測試案例結果。消費者無法：
+  在 CodeBuild 主控台中檢視共用報告群組或其報告。
+  編輯共用報告群組。
+  使用專案中共用報告群組的 ARN 來執行報告。指定共用報告群組的專案建置會失敗。

您可以使用 CodeBuild 主控台將報告群組新增至現有的資源共享。如果您想要將報告群組新增至新的資源共用，需先在 [AWS RAM 主控台](https://console.aws.amazon.com/ram)中建立它。

若要與組織單位或整個組織共用報告群組，必須啟用透過 AWS Organizations來共用的功能。如需詳細資訊，請參閱《*AWS RAM 使用者指南*》中的[透過 AWS Organizations啟用共用](https://docs.aws.amazon.com/ram/latest/userguide/getting-started-sharing.html)。

您可以使用 CodeBuild AWS RAM 主控台、主控台或 AWS CLI 來共用您擁有的報告群組。

**先決條件**  
若要共用報告群組， AWS 您的帳戶必須擁有該群組。您無法將已共用給您的報告群組再共用出去。

**共用您擁有的報告群組 (CodeBuild 主控台）**

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

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

1.  選擇您要共用的專案，然後選擇 **Share (共用)**。如需詳細資訊，請參閱*《AWS RAM 使用者指南》*中的[建立資源共用](https://docs.aws.amazon.com/ram/latest/userguide/getting-started-sharing.html#getting-started-sharing-create)。

**共用您擁有的報告群組AWS RAM （主控台）**  
請參閱 *AWS RAM 使用者指南*中的[建立資源共用](https://docs.aws.amazon.com/ram/latest/userguide/working-with-sharing.html#working-with-sharing-create)。

**共用您擁有的報告群組 (AWS RAM 命令）**  
使用 [create-resource-share](https://docs.aws.amazon.com/cli/latest/reference/ram/create-resource-share.html) 命令。

 **共用您擁有的報告群組 (CodeBuild 命令）** 

使用 [put-resource-policy](https://docs.aws.amazon.com/cli/latest/reference/codebuild/put-resource-policy.html) 命令：

1. 建立名為 `policy.json` 的檔案，並將以下命令複製到其中。

------
#### [ JSON ]

****  

   ```
   {
      "Version":"2012-10-17",		 	 	 
      "Statement":[{
        "Effect":"Allow",
        "Principal":{
          "AWS":"111122223333"
        },
        "Action":[
          "codebuild:BatchGetReportGroups",
          "codebuild:BatchGetReports",
          "codebuild:ListReportsForReportGroup",
          "codebuild:DescribeTestCases"],
        "Resource":"arn:aws:iam::*:role/Service*"
      }]
    }
   ```

------

1. 使用報告群組 ARN 和識別符更新 `policy.json`，以與之共用。下列範例使用 Alice 的 ARN 和 123456789012 所識別 AWS 帳戶的根使用者`arn:aws:codebuild:us-west-2:123456789012:report-group/my-report-group`，授予報告群組的唯讀存取權。

------
#### [ JSON ]

****  

   ```
   {
      "Version":"2012-10-17",		 	 	 
      "Statement":[{
        "Effect":"Allow",
        "Principal":{
          "AWS": [
             "arn:aws:iam::123456789012:user/Alice",
             "123456789012"
           ]
        },
        "Action":[
          "codebuild:BatchGetReportGroups",
          "codebuild:BatchGetReports",
          "codebuild:ListReportsForReportGroup",
          "codebuild:DescribeTestCases"],
        "Resource":"arn:aws:codebuild:us-west-2:123456789012:report-group/my-report-group"
      }]
    }
   ```

------

1. 執行下列命令。

   ```
   aws codebuild put-resource-policy --resource-arn report-group-arn --policy file://policy.json
   ```

## 相關服務
<a name="report-groups-sharing-related"></a>

報告群組共用與 AWS Resource Access Manager (AWS RAM) 整合，這項服務可讓您與任何 AWS 帳戶或透過 共用 AWS 資源 AWS Organizations。與 共用您擁有的資源 AWS RAM，方法是建立*資源共用*，指定要共用的資源和取用者。消費者可以是 中的個別 AWS 帳戶 AWS Organizations、組織單位或整個組織 AWS Organizations。

如需詳細資訊，請參閱*「[AWS RAM 使用者指南」](https://docs.aws.amazon.com/ram/latest/userguide/)*。

# 存取與您共用的報告群組
<a name="report-groups-sharing-access-prereqs"></a>

若要存取共用報告群組，消費者的 IAM 角色需要 `BatchGetReportGroups` 許可。您可以將下列政策連接至其 IAM 角色：

```
{
    "Effect": "Allow",
    "Resource": [
        "*"
    ],
    "Action": [
        "codebuild:BatchGetReportGroups"
    ]
}
```

 如需詳細資訊，請參閱[使用 的身分型政策 AWS CodeBuild](auth-and-access-control-iam-identity-based-access-control.md)。

# 取消共用共用報告群組
<a name="report-groups-sharing-unshare"></a>

唯有其擁有者才能存取已取消共享的報告群組，包括其報告及測試案例結果。如果您取消共用報告群組，您之前與其共用的任何 AWS 帳戶或使用者都無法存取報告群組、其報告或報告中測試案例的結果。

若要取消共享您擁有的已共用報告存取，您必須從資源共享中移除它。您可以使用 AWS RAM 主控台或 AWS CLI 來執行此操作。

**取消共用您擁有的共用報告群組AWS RAM （主控台）**  
請參閱《*AWS RAM 使用者指南*》中的[更新資源共享](https://docs.aws.amazon.com/ram/latest/userguide/working-with-sharing.html#working-with-sharing-update)。

**取消共用您擁有的共用報告群組 (AWS RAM 命令）**  
使用 [disassociate-resource-share](https://docs.aws.amazon.com/cli/latest/reference/ram/disassociate-resource-share.html) 命令。

 ** 取消共用您擁有的 CodeBuild 命令的報告群組）** 

執行 [delete-resource-policy](https://docs.aws.amazon.com/cli/latest/reference/codebuild/delete-resource-policy.html) 命令並指定您要取消共享之報告群組的 ARN：

```
aws codebuild delete-resource-policy --resource-arn report-group-arn
```

# 識別共用報告群組
<a name="report-groups-sharing-identify"></a>

擁有者和取用者可以使用 AWS CLI 來識別共用報告群組。

若要識別並取得共用報告群組及其報告的資訊，請使用下列命令：
+  若要查看與您共用的報告群組 ARN，請執行 `[list-shared-report-groups](https://docs.aws.amazon.com/cli/latest/reference/codebuild/list-shared-report-groups.html)`：

  ```
  aws codebuild list-shared-report-groups
  ```
+  若要查看在報告存取中的報告 ARN，請使用報告群組 ARN 執行 `[list-reports-for-report-group](https://docs.aws.amazon.com/cli/latest/reference/codebuild/list-reports-for-report-group.html)`：

  ```
  aws codebuild list-reports-for-report-group --report-group-arn report-group-arn
  ```
+  若要查看報告中測試案例的相關資訊，請使用報告 ARN 執行 `[describe-test-cases](https://docs.aws.amazon.com/cli/latest/reference/codebuild/describe-test-cases.html)`：

  ```
  aws codebuild describe-test-cases --report-arn report-arn
  ```

   輸出看起來如下：

  ```
  {
      "testCases": [
          {
              "status": "FAILED",
              "name": "Test case 1",
              "expired": 1575916770.0,
              "reportArn": "report-arn",
              "prefix": "Cucumber tests for agent",
              "message": "A test message",
              "durationInNanoSeconds": 1540540,
              "testRawDataPath": "path-to-output-report-files"
          },
          {
              "status": "SUCCEEDED",
              "name": "Test case 2",
              "expired": 1575916770.0,
              "reportArn": "report-arn",
              "prefix": "Cucumber tests for agent",
              "message": "A test message",
              "durationInNanoSeconds": 1540540,
              "testRawDataPath": "path-to-output-report-files"
          }
      ]
  }
  ```

# 共用報告群組的許可
<a name="report-groups-sharing-perms"></a>

## 擁有者的許可
<a name="report-groups-perms-owner"></a>

報告群組的擁有者可以編輯報告群組，並在專案中指定該報告群組，以執行報告。

## 消費者的許可
<a name="report-groups-perms-consumer"></a>

報告群組消費者可以檢視報告群組、其報告，以及其報告的測試案例結果。消費者無法編輯報告群組或其報告，也無法用它來建立報告。

# 指定測試檔案
<a name="report-group-test-cases"></a>

 您可以在建置專案 buildspec 檔案的 `reports` 區段中，指定每個報告群組的測試結果檔案及其位置。如需詳細資訊，請參閱[Reports syntax in the buildspec file](build-spec-ref.md#reports-buildspec-file)。

 以下是指定建置專案的兩個報告群組的範例 `reports` 區段。一個以其 ARN 指定，另一個則以名稱指定。`files` 區段指定包含測試案例結果的檔案。選用 `base-directory` 區段指定測試案例檔案所在的目錄。選用`discard-paths`區段指定是否捨棄上傳至 Amazon S3 儲存貯體之測試結果檔案的路徑。

```
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
    
  sampleReportGroup: #Cucumber reports from json plugin
    files:
      - 'cucumber-json/target/cucumber-json-report.json'
    file-format: CUCUMBERJSON #Type of the report, defaults to JUNITXML
```

# 指定測試命令
<a name="report-group-test-case-commands"></a>

 您可以在 buildspec 檔案的 `commands` 區段中指定執行測試案例的命令。這些命令會在 buildspec 檔案的 `reports` 區段中執行為報告群組指定的測試案例。以下範例 `commands` 區段包括要執行測試檔案中測試的命令：

```
commands:
    - echo Running tests for surefire junit
    - mvn test -f surefire/pom.xml -fn
    - echo
    - echo Running tests for cucumber with json plugin
    - mvn test -Dcucumber.options="--plugin json:target/cucumber-json-report.json" -f cucumber-json/pom.xml -fn
```

如需詳細資訊，請參閱[Buildspec 語法](build-spec-ref.md#build-spec-ref-syntax)。

# 在 中標記報告群組 AWS CodeBuild
<a name="how-to-tag-report-group"></a>

*標籤*是您或 AWS 指派給 AWS 資源的自訂屬性標籤。每個 AWS 標籤有兩個部分：
+ *標籤鍵* (例如，`CostCenter`、`Environment`、`Project` 或 `Secret` )。標籤鍵會區分大小寫。
+ 一個名為*標籤值* (例如，`111122223333`、`Production` 或團隊名稱) 的選用欄位。忽略標籤值基本上等同於使用空字串。與標籤鍵相同，標籤值會區分大小寫。

這些合稱為鍵值組。對於報告群組上標籤數目的限制，以及標籤金鑰和值的限制，請參閱[Tags (標籤)](limits.md#tag-limits)。

標籤可協助您識別和組織 AWS 資源。許多 AWS 服務支援標記，因此您可以將相同的標籤指派給來自不同 服務的資源，以指出資源相關。例如，您可以將相同的標籤指派給指派給 Amazon S3 儲存貯體的 CodeBuild 報告群組。如需使用標籤的詳細資訊，請參閱[標記最佳實務](https://d1.awsstatic.com/whitepapers/aws-tagging-best-practices.pdf)白皮書。

在 CodeBuild 中，主要資源是報告群組和專案。您可以使用 CodeBuild 主控台、 AWS CLI、CodeBuild APIs或 AWS SDKs 來新增、管理和移除報告群組的標籤。除了識別、組織和追蹤具有標籤的報告群組之外，您還可以在 IAM 政策中使用標籤，以協助控制誰可以檢視報告群組並與之互動。如需以標籤為基礎的存取政策範例，請參閱[使用標籤控制對 AWS CodeBuild 資源的存取](auth-and-access-control-using-tags.md)。

**Topics**
+ [將標籤新增至報告群組](how-to-tag-report-group-add.md)
+ [檢視報告群組的標籤](how-to-tag-report-group-list.md)
+ [編輯報表群組的標籤](how-to-tag-report-group-update.md)
+ [從報告群組移除標籤](how-to-tag-report-group-delete.md)

# 將標籤新增至報告群組
<a name="how-to-tag-report-group-add"></a>

將標籤新增至報告群組可協助您識別和組織資源，並管理對這些 AWS 資源的存取。首先，將一或多個標籤 (金鑰值對) 新增到報告群組。請記住，報告群組的標籤數目有所限制。金鑰和值欄位可使用的字數有所限制。如需詳細資訊，請參閱[Tags (標籤)](limits.md#tag-limits)。擁有標籤後，您可以建立 IAM 政策，以根據這些標籤管理對報告群組的存取。您可以使用 CodeBuild 主控台或 AWS CLI 將標籤新增至報告群組。

**重要**  
將標籤新增到報告群組可能會影響該報告群組的存取權。將標籤新增至報告群組之前，請務必檢閱任何可能使用標籤來控制對報告群組等資源的存取的 IAM 政策。如需以標籤為基礎的存取政策範例，請參閱[使用標籤控制對 AWS CodeBuild 資源的存取](auth-and-access-control-using-tags.md)。

如需在建立政策時，將標籤新增至報告群組的詳細資訊，請參閱[建立報告群組 (主控台)](report-group-create.md#test-report-group-create-console)。

**Topics**
+ [將標籤新增至報告群組 (主控台)](#how-to-tag-report-group-add-console)
+ [將標籤新增至報告群組 (AWS CLI)](#how-to-tag-report-group-add-cli)

## 將標籤新增至報告群組 (主控台)
<a name="how-to-tag-report-group-add-console"></a>

您可以使用 CodeBuild 主控台，將一或多個標籤新增至 CodeBuild 報告群組。

1. 前往 [https://console.aws.amazon.com/codebuild/](https://console.aws.amazon.com/codebuild/) 開啟 CodeBuild 主控台。

1. 在 **Report groups (報告群組)** 中，選擇您要新增標籤的報告群組名稱。

1. 在導覽窗格中，選擇**設定**。

1. 如果沒有任何標籤新增至報告群組，請選擇 **Add tag (新增標籤)**。您也可以選擇 **Edit (編輯)**，然後選擇 **Add tag (新增標籤)**。

1. 在 **Key (金鑰)** 中，輸入標籤的名稱。您可以在 **Value (值)** 中為標籤新增選用值。

1. (選用) 若要新增另一個標籤，再選擇 **Add tag (新增標籤)** 一次。

1. 當您完成新增標籤的作業時，請選擇 **Submit (提交)**。

## 將標籤新增至報告群組 (AWS CLI)
<a name="how-to-tag-report-group-add-cli"></a>

若要在建立政策時，將標籤新增至報告群組，請參閱[建立報告群組 (CLI)](report-group-create.md#test-report-group-create-cli)。在 `CreateReportGroup.json` 中，新增您的標籤。

 若要將標籤新增至現有的報告群組，請參閱[更新報告群組 (CLI)](report-group-export-settings.md#update-report-group-cli)，並在 `UpdateReportGroupInput.json` 中新增標籤。

在這些步驟中，我們假設您已經安裝新版 AWS CLI 或更新到最新版本。如需詳細資訊，請參閱[安裝 AWS Command Line Interface](https://docs.aws.amazon.com/cli/latest/userguide/installing.html)。

# 檢視報告群組的標籤
<a name="how-to-tag-report-group-list"></a>

標籤可協助您識別和組織 AWS 資源，並管理對資源的存取。如需使用標籤的詳細資訊，請參閱[標記最佳實務](https://d1.awsstatic.com/whitepapers/aws-tagging-best-practices.pdf)白皮書。如需以標籤為基礎的存取政策範例，請參閱[Deny or allow actions on report groups based on resource tags](auth-and-access-control-using-tags.md#report-group-tag-policy-example)。

## 檢視報告群組的標籤 (主控台)
<a name="how-to-tag-report-group-list-console"></a>

您可以使用 CodeBuild 主控台來檢視與 CodeBuild 報告群組相關聯的標籤。

1. 前往 [https://console.aws.amazon.com/codebuild/](https://console.aws.amazon.com/codebuild/) 開啟 CodeBuild 主控台。

1. 在 **Report groups (報告群組)** 中，選擇您要檢視標籤的報告群組名稱。

1. 在導覽窗格中，選擇**設定**。

## 檢視報告群組的標籤 (AWS CLI)
<a name="how-to-tag-report-group-list-cli"></a>

請依照下列步驟使用 AWS CLI 檢視報告群組的 AWS 標籤。如果未新增任何標籤，會傳回空白的標籤清單。

1.  使用 主控台或 AWS CLI 來尋找報告群組的 ARN。記下該 ARN。

------
#### [ AWS CLI ]

    執行下列命令。

   ```
   aws list-report-groups
   ```

    此命令會傳回類似如下的 JSON 格式資訊：

   ```
   {
       "reportGroups": [
           "arn:aws:codebuild:region:123456789012:report-group/report-group-1",
           "arn:aws:codebuild:region:123456789012:report-group/report-group-2",
           "arn:aws:codebuild:region:123456789012:report-group/report-group-3"
       ]
   }
   ```

   報告群組 ARN 以其名稱結尾，您可以用來識別報告群組的 ARN。

------
#### [ Console ]

   1. 前往 [https://console.aws.amazon.com/codebuild/](https://console.aws.amazon.com/codebuild/) 開啟 CodeBuild 主控台。

   1. 在 **Report groups (報告群組)** 中，選擇帶有您要檢視之標籤的報告群組名稱。

   1.  在 **Configuration (組態)** 中，找出報告群組的 ARN。

------

1.  執行下列命令。使用您針對 `--report-group-arns` 參數記下的 ARN。

   ```
   aws codebuild batch-get-report-groups --report-group-arns arn:aws:codebuild:region:123456789012:report-group/report-group-name
   ```

    如果成功，此命令會傳回 JSON 格式的資訊，其包含類似如下的 `tags` 區段：

   ```
   {
       ...                        
       "tags": {
           "Status": "Secret",
           "Project": "TestBuild"
       }
       ...
   }
   ```

# 編輯報表群組的標籤
<a name="how-to-tag-report-group-update"></a>

您可以變更與報告群組相關聯標籤的值。您也可以變更金鑰的名稱，這相當於移除目前的標籤，並新增具有新名稱和與其他金鑰相同值的不同標籤。請記住金鑰和值欄位可使用的字元有所限制。如需詳細資訊，請參閱[Tags (標籤)](limits.md#tag-limits)。

**重要**  
編輯報告群組的謙可能會影響該報告群組的存取權。在編輯報告群組標籤的名稱 （索引鍵） 或值之前，請務必檢閱任何可能使用標籤索引鍵或值的 IAM 政策，以控制對報告群組等資源的存取。如需以標籤為基礎的存取政策範例，請參閱[Deny or allow actions on report groups based on resource tags](auth-and-access-control-using-tags.md#report-group-tag-policy-example)。

## 編輯報告群組的標籤 (主控台)
<a name="how-to-tag-report-group-update-console"></a>

您可以使用 CodeBuild 主控台來編輯與 CodeBuild 報告群組相關聯的標籤。

1. 前往 [https://console.aws.amazon.com/codebuild/](https://console.aws.amazon.com/codebuild/) 開啟 CodeBuild 主控台。

1. 在 **Report groups (報告群組)** 中，選擇您要編輯標籤的報告群組名稱。

1. 在導覽窗格中，選擇**設定**。

1. 選擇**編輯**。

1. 執行以下任意一項：
   + 若要變更標籤，請在 **Key (金鑰)** 輸入新的名稱。變更標籤名稱等於移除標籤並使用新的金鑰名稱新增一個新的標籤。
   + 若要變更標籤的值，請輸入新的值。如果您想要變更值為沒有，請刪除目前的值並保留欄位空白。

1. 當您完成編輯標籤，選擇 **Submit (提交)**。

## 編輯報表群組的標籤 (AWS CLI)
<a name="how-to-tag-report-group-update-cli"></a>

 若要新增、變更或刪除報告群組的標籤，請參閱[更新報告群組 (CLI)](report-group-export-settings.md#update-report-group-cli)。更新 `UpdateReportGroupInput.json` 中的標籤。

# 從報告群組移除標籤
<a name="how-to-tag-report-group-delete"></a>

您可以移除一或多個與報告群組相關聯的標籤。移除標籤不會從與該標籤相關聯的其他 AWS 資源中刪除標籤。

**重要**  
移除報表群組的標籤可能會影響該報表群組的存取權。從報告群組移除標籤之前，請務必檢閱任何可能使用標籤金鑰或值的 IAM 政策，以控制對報告群組等資源的存取。如需以標籤為基礎的存取政策範例，請參閱[使用標籤控制對 AWS CodeBuild 資源的存取](auth-and-access-control-using-tags.md)。

## 從報告群組移除標籤 (主控台)
<a name="how-to-tag-report-group-delete-console"></a>

您可以使用 CodeBuild 主控台來移除標籤與 CodeBuild 報告群組之間的關聯。

1. 前往 [https://console.aws.amazon.com/codebuild/](https://console.aws.amazon.com/codebuild/) 開啟 CodeBuild 主控台。

1. 在 **Report groups (報告群組)** 中，選擇您要移除標籤的報告群組名稱。

1. 在導覽窗格中，選擇**設定**。

1. 選擇**編輯**。

1. 尋找您想要移除的標籤，然後選擇 **Remove tag (移除標籤)**。

1. 當您完成移除標籤，請選擇 **Submit (提交)**。

## 從報告群組移除標籤 (AWS CLI)
<a name="how-to-tag-report-group-delete-cli"></a>

請依照下列步驟，使用 從 CodeBuild 報告群組 AWS CLI 中移除標籤。移除標籤並不會將其刪除，只會移除標籤和報告群組之間的關聯。

**注意**  
如果您刪除 CodeBuild 報告群組，所有標籤關聯都會從已刪除的報告群組中移除。您不需要在刪除報告群組之前移除標籤。

 若要將一或多個標籤從報告群組中刪除，請參閱[編輯報表群組的標籤 (AWS CLI)](how-to-tag-report-group-update.md#how-to-tag-report-group-update-cli)。使用未包含您要刪除之標籤的已更新標籤清單，來更新 JSON 格式資料中的 `tags` 區段。如果您要刪除所有標籤，請將 `tags` 區段更新為：

```
"tags: []"
```

# 更新報告群組
<a name="report-group-export-settings"></a>

 當您更新報告群組時，您可以指定是否將原始測試結果資料匯出至 Amazon S3 儲存貯體中的檔案的相關資訊。如果您選擇匯出至 S3 儲存貯體，您可以針對報告群組指定下列項目：
+ 原始測試結果檔案是否以 ZIP 檔案壓縮。
+ 原始測試結果檔案是否加密。您可以使用下列其中一種形式來指定加密：
  +  AWS 受管金鑰 適用於 Amazon S3 的 。
  + 您建立和設定的客戶受管金鑰。

如需詳細資訊，請參閱[資料加密](security-encryption.md)。

如果您使用 AWS CLI 更新報告群組，也可以更新或新增標籤。如需詳細資訊，請參閱[在 中標記報告群組 AWS CodeBuild標記報表群組](how-to-tag-report-group.md)。

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

**Topics**
+ [更新報告群組 (主控台)](#update-report-group-console)
+ [更新報告群組 (CLI)](#update-report-group-cli)

## 更新報告群組 (主控台)
<a name="update-report-group-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. 選擇您想要更新的報告群組。

1. 選擇**編輯**。

1. 選取或清除**備份至 Amazon S3**。如果選取此選項，請指定匯出設定：

   1. 針對 **S3 bucket name (S3 儲存貯體名稱)**，輸入 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 (停用成品)** 可讓您停用加密。如果您想要共享測試結果，或發佈至靜態網站，您可以選擇此選項。(動態網站可以執行程式碼，以解密測試結果。)

## 更新報告群組 (CLI)
<a name="update-report-group-cli"></a>

使用下列程序來更新使用 的報告群組 AWS CLI。

**更新報告群組**

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

1. 將以下內容複製到 `UpdateReportGroupInput.json`：

   ```
   {
       "arn": "",
       "exportConfig": {
           "exportConfigType": "S3",
           "s3Destination": {
               "bucket": "bucket-name", 
               "path": "path", 
               "packaging": "NONE | ZIP",
               "encryptionDisabled": "false",
               "encryptionKey": "your-key"
            }
        },
        "tags": [
           {
               "key": "tag-key",
               "value": "tag-value"
           }
        ]
   }
   ```

1. 在 `arn` 行中輸入您報告群組的 ARN (例如，`"arn":"arn:aws:codebuild:region:123456789012:report-group/report-group-1")`。

1. 使用您要套用至報告群組的更新來更新 `UpdateReportGroupInput.json`。
   + 如果您要更新報告群組，讓原始測試結果檔案匯出至 S3 儲存貯體，請更新 `exportConfig` 區段。以您的 S3 儲存貯體名稱取代 `bucket-name` ，並以您想要在 S3 儲存貯體中匯出檔案的路徑取代 `path`。如果您想要壓縮匯出的檔案，請為 `packaging` 指定 `ZIP`。否則請指定 `NONE`。使用 `encryptionDisabled` 指定是否要將匯出的檔案加密。如果您加密匯出的檔案，請輸入您的客戶受管金鑰。
   + 如果您要更新報告群組，讓報告群組不會匯出原始測試結果檔案至 S3 儲存貯體，請使用下列 JSON 更新 `exportConfig` 區段：

     ```
     { 
       "exportConfig": {
           "exportConfigType": "NO_EXPORT"
       }
     }
     ```
   + 如果您要更新報告群組的標籤，請更新 `tags` 區段。您可以變更、新增或移除標籤。如果您想移除所有標籤，請使用以下 JSON 更新之：

     ```
     "tags": []
     ```

1.  執行以下命令：

   ```
   aws codebuild update-report-group \
   --cli-input-json file://UpdateReportGroupInput.json
   ```