CodePipeline构建中的secondary-artifacts部分提到的构件未上传到S3桶

50次阅读
没有评论

问题描述

在使用CodePipeline项目构建应用程序时,通过Maven构建并将其构件上传到S3桶。用户尝试通过CodeBuild将多个构件作为单个zip文件上传到S3桶。以下是用户的示例buildspec.yml文件。

version: 0.2
phases:
  install:
    runtime-versions:
      java: openjdk8
    commands:
      - apt update -y && apt install maven -y
      - echo Install phase started on `date`
      - echo Install phase ended on `date`
  pre_build:
    commands:
      - echo Pre_build phase started on `date`
      - bash pipelines/aws/scripts/onCheckout.sh
      - echo Pre_build phase ended on `date`
  build:
    commands:
      - echo Build phase started on `date`
      - bash pipelines/aws/scripts/onBuild.sh
      - echo Build phase ended on `date`
  post_build:
    commands:
      - echo Post_build phase started on `date`
      - bash pipelines/aws/scripts/onPackage.sh
      - bash pipelines/aws/scripts/onPublish.sh
      - bash pipelines/aws/scripts/onPromote.sh
      - echo Post_build phase ended on `date`
      - echo $CODEBUILD_SRC_DIR
artifacts:
  files:
    - pipelines/**/*
    - target/spring-petclinic-2.0.0.jar
  base-directory: $CODEBUILD_SRC_DIR
secondary-artifacts:
  artifact1:
    files:
      - pipelines/aws/appspec.yml
    base-directory: $CODEBUILD_SRC_DIR
    discard-paths: yes

用户提供了构建输出和问题代码示例,但secondary-artifacts中提到的构件由于未知原因完全被忽略。用户想知道是否遗漏了某些参数。

解决方案

请注意以下操作可能因版本差异而有所不同,建议在执行操作前做好备份。
在CodeBuild中,如果secondary-artifacts中提到的构件未上传到S3桶,您可以执行以下步骤来解决问题:

  1. 打开您的CodeBuild项目设置。
  2. 在“Artifacts”部分,您将看到一个“Add Artifact”按钮。
  3. 点击该按钮,并引用您在secondary-artifacts中提到的构件。
  4. 确保您提供了正确的构件名称、文件路径和基础目录。

在您的示例buildspec.yml文件中,您已经定义了secondary-artifacts,但是在构建中并没有添加这些构件。通过按照上述步骤将这些构件添加到Artifacts配置中,您应该能够确保它们被上传到S3桶中。

以下是一个示例buildspec.yml文件,演示了如何添加secondary-artifacts中提到的构件:

version: 0.2
phases:
  # ...
artifacts:
  files:
    - pipelines/**/*
    - target/spring-petclinic-2.0.0.jar
  base-directory: $CODEBUILD_SRC_DIR
  secondary-artifacts:
    artifact1:
      files:
        - pipelines/aws/appspec.yml
      base-directory: $CODEBUILD_SRC_DIR
      discard-paths: yes

请确保在配置中使用正确的构件名称、文件路径和基础目录,以便正确地引用并上传您的secondary构件。完成后,您应该能够在CodePipeline构建中将这些构件一同上传到S3桶中。

如果问题仍然存在,您可能需要检查CodeBuild的日志和错误消息,以查找更多关于为什么secondary构件未上传的信息。同时,确保您的构建操作脚本正确处理了这些构件,并且没有意外地删除或移动它们。

正文完