LoginSignup
5
3

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