DEV Community

Yuta Goto
Yuta Goto

Posted on

3 1

CircleCIで変数を扱う

CircleCIの実行環境もシンプルなシェルスクリプトなので、環境変数に代入すれば他のステップで使用することができます。

https://circleci.com/docs/2.0/env-vars/

サンプルリポジトリ


コード

version: 2.1

jobs:
  build:
    docker:
      - image: circleci/ruby:2.6.3-stretch-node
    steps:
      - checkout
      - run:
          command: ruby app.rb
      - run:
          command: echo "export RUBY_TEXT='$(ruby app.rb)'" >> $BASH_ENV
      - run:
          command: echo "${RUBY_TEXT}"

workflows:
  build:
    jobs:
      - build
Enter fullscreen mode Exit fullscreen mode

実行結果

Alt Text

解説

echo "export RUBY_TEXT='$(ruby app.rb)'" >> $BASH_ENVruby app.rb の実行結果を RUBY_TEXT に代入して環境変数として登録しています。

活用方法の例としては、 RUBY_TEXT をSlackなどに送信があります。

--

局所的なtipsですが、役に立てれば幸いです。

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay