AWS CodePipeline BuildAction 未检测到 buildspec.yml 个次要工件

AWS CodePipeline BuildAction not detecting buildspec.yml secondary artifacts

我正在尝试使用辅助工件将网页文件与 cdk 生成的 Stack 文件分开。但是来自管道的 BuildAction 没有检测到将 Web 文件与 Stack 文件分开的次要工件。

我已经尝试遵循与 buildspec.yml 以及多个来源和多个输出相关的 AWS 文档的建议,但无法使其正常工作。

这是我的构建操作的 cdk 代码。

const buildStage = pipeline.addStage({ stageName: 'Build'});
        const buildOutputWeb = new Artifact("webapp")
        const buildOutputTemplates = new Artifact("template")
        const project = new PipelineProject(this, 'Wavelength_build', {
            environment: {
                buildImage: LinuxBuildImage.STANDARD_3_0
            },
            projectName: 'WebBuild'
        });

        buildStage.addAction(new CodeBuildAction({
            actionName: 'Build',
            project,
            input: sourceOutput,
            outputs: [buildOutputWeb, buildOutputTemplates]
        }));

这是与生成的堆栈文件中的构建操作相关的部分

{
            "Actions": [
              {
                "ActionTypeId": {
                  "Category": "Build",
                  "Owner": "AWS",
                  "Provider": "CodeBuild",
                  "Version": "1"
                },
                "Configuration": {
                  "ProjectName": {
                    "Ref": "Wavelengthbuild7D63C781"
                  }
                },
                "InputArtifacts": [
                  {
                    "Name": "SourceOutput"
                  }
                ],
                "Name": "Build",
                "OutputArtifacts": [
                  {
                    "Name": "webapp"
                  },
                  {
                    "Name": "template"
                  }
                ],
                "RoleArn": {
                  "Fn::GetAtt": [
                    "WavelengthPipelineBuildCodePipelineActionRoleC08CF8E2",
                    "Arn"
                  ]
                },
                "RunOrder": 1
              }
            ],
            "Name": "Build"
          },

这是我的 buildspec.yml

version: 0.2
env:
  variables:
    S3_BUCKET: "wavelenght-web.ronin-ddd-dev-web.net"
phases:
  install:
    runtime-versions:
      nodejs: 10
  pre_build:
    commands:
      - echo Installing source NPM dependencies...
      - npm install -g @angular/cli
      - npm install typescript -g
      - npm install -D lerna
  build:
    commands:
      - echo Build started on `date`
      - npm run release
      - cd $CODEBUILD_SRC_DIR
  post_build:
     commands:
      - echo Build completed on `date`
artifacts:
  files:
    - '**/*'
  secondary-artifacts:
    artifact1:
      base-directory: $CODEBUILD_SRC_DIR
      files:
        - 'packages/website/dist/**/*'
      name: webapp
      discard-paths: yes
    artifact2:
      base-directory: $CODEBUILD_SRC_DIR
      files:
        - '*/WavelengthAppStack.template.json'
      name: template
      discard-paths: yes
    

webapptemplate 二次吸引(来自 docs):

Each artifact identifiers in this block must match an artifact defined in the secondaryArtifacts attribute of your project.

在您发布的问题中,我没有看到任何证据表明您的构建项目中定义了次级输出。这可能解释了为什么您会收到有关“无定义”的错误。

我想通了。 事实证明,次要工件中的名称属性不会更改标识符。 我的 buildspec.yml 工件现在看起来像这样。

artifacts:
  secondary-artifacts:
    webapp:
      base-directory: packages/website/dist
      files:
        - '**/*'
      name: webapp
    template:
      base-directory: packages/infrastructure/cdk.out
      files:
        - 'WavelengthAppStack.template.json'
      name: template

请注意,现在不是 artifact1:,然后是该工件的所有数据,而是 webapp:,然后是所有数据。