2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

CodeBuild の buildspec.yml で `YAML_FILE_ERROR Message: did not find expected comment or line break` が発生

Last updated at Posted at 2019-10-20

現象

buildspec.yml で CodeBuild を動かすと、以下エラーが発生してビルドがストップする。

[Container] 2019/10/16 11:28:42 Phase complete: DOWNLOAD_SOURCE State: FAILED 
[Container] 2019/10/16 11:28:42 Phase context status code: YAML_FILE_ERROR Message: did not find expected comment or line break at line 20

環境

  • buildspec.yml の version: 0.2

原因

エラーが示した line 20 は以下の $DRYRUN ... の行。

  build:
    commands:
      - [[ $DRYRUN != 1 ]] || bash -c "./deploy.sh -e ${BUILD_STAGE} ${MODE}"

当該行は、そもそも YAML の構文に従っていなかった。具体的には論理和 || の部分。
| が複数行を記述するための予約文字になっているため、文字列として認識されない。

同様に &&& がアンカーの予約文字になっている。

対応

ダブルクオートでくくることで構文エラーを回避できる。

      - "[[ $DRYRUN != 1 ]] || bash -c \"./deploy.sh -e ${BUILD_STAGE} ${MODE}\""

参考

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?