LoginSignup
2
0

More than 3 years have passed since last update.

ローカル環境でCircleCIのCLIの使用する

Posted at

備忘録です

参考

CircleCI のローカル CLI の使用 - CircleCI

準備

インストール

$ brew install circleci

パーソナルAPIトークンの発行

CircleCI

セットアップ

$ circleci setup
  • トークンとホストを求められるので入力。(circleci.comを使用している場合はホストはデフォルトでOK)
  • ~/.circleci ディレクトリが生成されるので、とりあえず CircleCI Config Builder を参考に適当な config.yml を作成
config.yml
version: 2.1
jobs:
  build:
    docker:
      - image: 'cimg/node:14.14.0'
    steps:
      - run: node --version

検証

$ circleci config validate -c .circleci/config.yml
もしくは
$ circleci config check -c .circleci/config.yml

Config file at .circleci/config.yml is valid.

実行

$ circleci build -c .circleci/config.yml

node --version
v14.14.0
Success!

※workflowが設定されている場合は失敗するのでJOB名で指定するとよい

config.yml
version: 2.1
jobs:
  node-version:
    docker:
      - image: 'cimg/node:14.14.0'
    steps:
      - run: node --version

workflows:
  node:
    jobs:
      - node-version
$ circleci build -c .circleci/config.yml

Error: 
Configuration errors: 1 error occurred:
    * Cannot find a job named `build` to run in the `jobs:` section of your configuration file.
If you expected a workflow to run, check your config contains a top-level key called 'workflows:'
$ circleci build -c .circleci/config.yml --job node-version

node --version
v14.14.0
Success!

制限事項

ローカル環境だといくつか制限があるので注意

  • Machine Executor
  • ワークフロー
    • 単一jobsしか実行できない
  • SSHキーの追加(add_ssh_keys)
  • キャッシュ(save_cache, restore_cache)
  • アーティファクトアップロード(store_artifacts)
  • Webで設定した環境変数
    • 実行時に -e で渡すことができる (circleci build -e VAR1=FOO -e VAR2=BAR)

開発リポジトリで使う

.circleci/config.yml を追加するだけでOK

デバッグ方法

stepに下記を追加

- run:
 name: 'Do not discard'
 no_output_timeout: 10m
 command: |-
  tail -f /dev/null
config.yml
version: 2.1

jobs:
  job-checkout:
    docker:
      - image: circleci/android:api-29
        environment:
          TZ: "Asia/Tokyo"
    steps:
      - checkout
      - run:
          name: 'Do not discard'
          no_output_timeout: 10m
          command: |-
            tail -f /dev/null

workflows:
  workflow-checkout:
    jobs:
      - job-checkout
$ circleci build -c .circleci/config.yml --job job-checkout

====>> Checkout code
Making checkout directory "/home/circleci/project"
Copying files from "/tmp/_circleci_local_build_repo" to "/home/circleci/project"

$ docker ps
$ docker exec -it [CONTAINER ID] /bin/sh; exit
$ ls /home/circleci/project
# checkoutを確認
2
0
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
2
0