AWS CodeBuild + CodePipeline:"No matching artifact paths found"

AWS CodeBuild + CodePipeline: "No matching artifact paths found"

我正在尝试让 CodePipeline 从 GitHub 获取我的代码并使用 CodeBuild 构建它。第一个(源)步骤工作正常。但是第二个(构建)步骤在 "UPLOAD_ARTIFACTS" 部分失败。以下是相关的日志语句:

[Container] 2017/01/12 17:21:31 Assembling file list
[Container] 2017/01/12 17:21:31 Expanding MyApp
[Container] 2017/01/12 17:21:31 Skipping invalid artifact path MyApp
[Container] 2017/01/12 17:21:31 Phase complete: UPLOAD_ARTIFACTS Success: false
[Container] 2017/01/12 17:21:31 Phase context status code: ARTIFACT_ERROR Message: No matching artifact paths found
[Container] 2017/01/12 17:21:31 Runtime error (No matching artifact paths found)

我的应用程序在其根文件夹中有一个 buildspec.yml。看起来像:

version: 0.1

phases:
  build:
    commands:
      - echo `$BUILD_COMMAND`

artifacts:
  discard-paths: yes
  files:
    - MyApp

我的 buildspec.yml 中的 "MyApp" 似乎应该有所不同,但我翻阅了所有 AWS 文档都无济于事(还有什么新内容?)。我怎样才能让它正确上传工件?

工件应该指的是从您的 Source 操作下载的文件或作为 CodePipeline 中 Build 操作的一部分生成的文件。例如,这是来自 buildspec.yml 我写的:

artifacts:
  files:
    - appspec.yml
    - target/SampleMavenTomcatApp.war
    - scripts/*

当我看到您在工件部分使用了 MyApp 时,我觉得您指的是 OutputArtifacts CodePipeline 的源操作。相反,您需要参考它下载并存储在那里的文件(即 S3)and/or 它生成并存储在那里。

您可以在此处找到使用 CodePipeline、CodeBuild、CodeDeploy 和 CodeCommit 的 CloudFormation 模板示例:https://github.com/stelligent/aws-codedeploy-sample-tomcat/blob/master/codebuild-cpl-cd-cc.json buildspec.yml 在同一个分支存储库中。

我遇到了类似的问题,解决问题的方法是 "packaging directories and files inside the archive with no further root folder creation"。

https://docs.aws.amazon.com/codebuild/latest/userguide/sample-war-hw.html

工件是您希望从构建过程中得到的东西——无论是以某种方式编译的还是直接从源代码复制的文件。所以构建服务器拉入代码,按照您的指令编译它,然后将指定的文件复制到 S3。

在我使用 Spring Boot + Gradle 的情况下,输出 jar 文件(当我 gradle bootJar 在我自己的系统上使用它时)被放置在 build/libs/demo1-0.0.1 -SNAPSHOT.jar,所以我在buildspec.yml中设置如下:

artifacts:
  files:
    - build/libs/*.jar

这个文件出现在 S3 中,可以选择在 zip and/or 子文件夹中,具体取决于在其余工件部分中选择的选项

Buildspec 工件是有关 CodeBuild 可以在何处找到构建输出以及 CodeBuild 如何准备将其上传到 Amazon S3 输出存储桶的信息。

对于错误 "No matching artifact paths found" 要检查的几件事:

  1. 在 buildspec.yml 文件上指定的工件文件具有 正确的路径和文件名。

artifacts: files: -'FileNameWithPath'

  1. 如果您使用的是 .gitignore 文件,请确保在 Artifacts 部分指定了文件 不包含在 .gitignore 文件中

希望对您有所帮助。

在我的例子中,我收到此错误是因为我在构建阶段更改了目录(我正在构建的 java 项目位于子目录中)并且没有更改回根目录。在构建阶段结束时添加 cd .. 就成功了。

尝试使用版本 0.2 的构建规范

这里是nodejs的典型例子

version: 0.2
phases:
  pre_build:
    commands:
      - echo Nothing to do in the pre_build phase...
  build:
    commands:
      - npm install
      - npm run build
  post_build:
    commands:
      - echo Build completed on
artifacts:
  files:
    - appspec.yml
    - build/*

如果您和我一样 运行 在 CodePipeline ar运行gement 中使用 Codebuild 时遇到这个问题。

您需要使用以下内容

- printf '[{"name":"container-name-here","imageUri":"%s"}]' $REPOSITORY_URI:$IMAGE_TAG > $CODEBUILD_SRC_DIR/imagedefinitions.json