5
3

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 3 years have passed since last update.

Buildspec.ymlでコマンド結果を変数として扱う

Posted at

#curlコマンドの結果をymlの変数に格納して使う

##envには文字列しか入らない
buildspecのenv>variablesには文字列しか入らないです。

例えば、

https://hoge/fuga/version

のように何かしらのversionを取得するapiがあったときに

env:
  variables:
      VERSION: `curl https://hoge/fuga/version | jq '.[].version'`

として VERSION に入れようとしてもコマンドがそのまま変数に入ってしまう。

phases で指定

以下のように phases の中で指定するとその後の処理で使えます。

phases:
  pre_build:
    commands:
      .........
  build:
    commands:
      - VERSION=`curl https://hoge/fuga/version | jq '.[].version'`
      - export VERSION
      - echo $VERSION
5
3
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
5
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?