上传 CodeBuild 工件 *如果* 它们存在

tgk*_*tgk 3 amazon-web-services aws-codepipeline aws-codebuild

我有一个简单的 CodeBuild 规范,它定义了测试运行后要上传的工件:

artifacts:
  files:
    - cypress/**/*.png
  discard-paths: yes
Run Code Online (Sandbox Code Playgroud)

仅当测试操作失败(捕获失败测试屏幕的屏幕截图)并成功上传到 S3 时才会生成这些工件。

在测试成功的情况下,不会.png生成任何文件并且 CodeBuild 操作失败:

[Container] 2018/09/21 20:06:34 Expanding cypress/**/*.png
[Container] 2018/09/21 20:06:34 Phase complete: UPLOAD_ARTIFACTS Success: false
[Container] 2018/09/21 20:06:34 Phase context status code: CLIENT_ERROR Message: no matching artifact paths found
Run Code Online (Sandbox Code Playgroud)

如果构建规范中存在文件,是否可以有条件地上传文件?

或者,我可以使用s3 cli-- 在这种情况下,我需要一种方法来轻松访问存储桶名称和工件键。

tgk*_*tgk 5

为了解决这个问题,如果构建成功,我将创建一个与 glob 模式匹配的占位符文件:

  post_build:
    commands:
      - if [ -z "$CODEBUILD_BUILD_SUCCEEDING" ]; then echo "Build failing, no need to create placeholder image"; else touch cypress/0.png; fi
artifacts:
  files:
    - cypress/**/*.png
  discard-paths: yes
Run Code Online (Sandbox Code Playgroud)