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ですが、役に立てれば幸いです。

Do your career a big favor. Join DEV. (The website you're on right now)

It takes one minute, it's free, and is worth it for your career.

Get started

Community matters

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

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay