

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

# を使用してスターターパイプラインをカスタマイズする方法 AWS SAM
<a name="serverless-customizing-starter-pipelines"></a>

CI/CD 管理者は、組織内のデベロッパーがパイプライン構成を作成するために使用できる、スターターパイプラインテンプレートおよび関連するガイド付きプロンプトをカスタマイズできます。

 AWS SAM CLI は、スターターテンプレートの作成時に Cookiecutter テンプレートを使用します。クッキーカッターテンプレートの詳細については、[Cookiecutter](https://cookiecutter.readthedocs.io/en/latest/README.html) を参照してください。

また、`sam pipeline init` コマンドを使用してパイプライン設定を作成するときに、 AWS SAM CLI がユーザに表示するプロンプトをカスタマイズすることもできます。ユーザプロンプトをカスタマイズするには、次の操作を行います。

1. **`questions.json` ファイルの作成** – `questions.json` ファイルはプロジェクトリポジトリのルートにある必要があります。これは、`cookiecutter.json` ファイルと同じディレクトリです。`questions.json` ファイルのスキーマを表示するには、「[questions.json.schema](https://github.com/aws/aws-sam-cli/blob/2b831b29f76ac9c4e0cbcbd68b37f8f664e136d8/samcli/lib/pipeline/init/questions.json.schema)」を参照してください。`questions.json` ファイルの例を表示するには、「[questions.json](https://github.com/aws/aws-sam-cli-pipeline-init-templates/blob/main/Jenkins/two-stage-pipeline-template/questions.json)」を参照してください。

1. **質問キーをクッキーカッターの名前でマッピングする** – `questions.json` ファイル内の各オブジェクトには cookieCutter テンプレートの名前と一致するキーが必要です。このキーマッチングは、 AWS SAM CLI が、ユーザプロンプトのレスポンスを Cookie Cutter テンプレートにマッピングする方法です。このキーマッチングの例については、このトピックの後半の [ファイルの例](#serverless-customizing-starter-pipelines-example-files) セクション。

1. **`metadata.json` ファイルの作成** – パイプラインが `metadata.json` ファイルで持つステージ数を宣言します。ステージ数は、`sam pipeline init` コマンドに、インフラストラクチャリソースを作成するステージ数に関する情報を求めるステージ数、または `--bootstrap` オプションの場合はステージ数を指示します。`metadata.json` 2 つのステージを持つパイプラインを宣言する ファイルの例については、[metadata.json](https://github.com/aws/aws-sam-cli-pipeline-init-templates/blob/main/Jenkins/two-stage-pipeline-template/metadata.json) を参照してください。

## プロジェクトの例
<a name="serverless-customizing-starter-pipelines-example-projects"></a>

以下に、Cookiecutter テンプレート、`questions.json` ファイル、および `metadata.json` ファイルをそれぞれ含むプロジェクトの例を示します。
+ Jenkins の例: [2 段階の Jenkins パイプラインテンプレート](https://github.com/aws/aws-sam-cli-pipeline-init-templates/tree/main/Jenkins/two-stage-pipeline-template)
+ CodePipeline の例: [2 段階の CodePipeline パイプラインテンプレート](https://github.com/aws/aws-sam-cli-pipeline-init-templates/tree/main/AWS-CodePipeline/two-stage-pipeline-template)

## ファイルの例
<a name="serverless-customizing-starter-pipelines-example-files"></a>

次の一連のファイルは、`questions.json` ファイルの質問が Cookiecutter テンプレートファイルのエントリにどのように関連付けられているかを示しています。これらの例はファイルスニペットであり、完全なファイルではないことに注意してください。完全なファイルの例については、このトピックの前半の [プロジェクトの例](#serverless-customizing-starter-pipelines-example-projects) セクションを参照してください。

例 **`questions.json`**:

```
{
  "questions": [{
    "key": "intro",
    "question": "\nThis template configures a pipeline that deploys a serverless application to a testing and a production stage.\n",
    "kind": "info"
  }, {
    "key": "pipeline_user_jenkins_credential_id",
    "question": "What is the Jenkins credential ID (via Jenkins plugin \"aws-credentials\") for pipeline user access key?",
    "isRequired": true
  }, {
    "key": "sam_template",
    "question": "What is the template file path?",
    "default": "template.yaml"
  }, {
    ...
```

例 **`cookiecutter.json`**:

```
{
  "outputDir": "aws-sam-pipeline",
  "pipeline_user_jenkins_credential_id": "",
  "sam_template": "",
    ...
```

例 **`Jenkinsfile`**:

```
pipeline {
  agent any
  environment {
    PIPELINE_USER_CREDENTIAL_ID = '{{cookiecutter.pipeline_user_jenkins_credential_id}}'
    SAM_TEMPLATE = '{{cookiecutter.sam_template}}'
    ...
```