【问题标题】:AWS CodePipeline BuildAction not detecting buildspec.yml secondary artifactsAWS CodePipeline BuildAction 未检测到 buildspec.yml 辅助工件
【发布时间】:2020-10-04 20:30:02
【问题描述】:

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

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

这是我用于构建操作的 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
    

【问题讨论】:

  • 任何 CodeBuild 错误?
  • CLIENT_ERROR: buildspec 中没有二级工件 webapp 的定义

标签: amazon-web-services pipeline aws-cdk aws-codepipeline


【解决方案1】:

我发现了问题所在。 事实证明,辅助工件中的 name 属性不会更改标识符。 我的 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:,然后是所有数据。

【讨论】:

    【解决方案2】:

    webapptemplate 二次吸引(来自docs):

    此块中的每个工件标识符必须与项目的 secondaryArtifacts 属性中定义的工件匹配。

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

    【讨论】:

    • 问题在于它适用于未在管道中使用的 CodeBuild 项目。 PipelineProject 没有引用辅助工件的属性
    • 我尝试添加辅助工件,但出现此错误。具有 CodePipeline 源的项目不能有辅助工件。请改用 CodeBuild 管道操作的 outputs 属性
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-18
    • 2017-05-28
    • 2020-04-30
    • 2020-08-17
    相关资源
    最近更新 更多