Help us understand the problem. What is going on with this article?

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

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
Terry3
works-hi
「はたらく」を楽しく!に向けて大手企業の人事業務から変えていく HR業界のリーディングカンパニー
https://www.works-hi.co.jp/
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした