2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

CircleCI のローカル CLI を使用する

Posted at

動機

ローカル環境でCircleCIの設定ファイルのデバッグを行いたかった.

環境

Homebrew: 2.2.2
circleci version: 0.1.5879+416032d

前提

CLI利用時の前提条件がいくつかある.リファレンスを参照.

手順

設定ファイルのバリデーション

# ヘルプ
$ circleci config validate -h
Check that the config file is well formed.

Usage:
  circleci config validate <path> [flags]
Aliases:
  validate, check

# 実行
$ circleci config validate -c .circleci/config.yml
$ circleci config check -c .circleci/config.yml

ジョブの実行

CircleCI v2.1はサポートされていないとのこと.以前Issueにはあがっていたが,クローズされてしまっているので,今後対応されるかは不明.

バージョン2.0用の設定に置き換え

# 標準出力
$ circleci config process .circleci/config.yml

# ファイル出力
$ circleci config process .circleci/config.yml > ci_local.yml

実行

失敗

$ circleci local execute -c ci_local.yml
Docker image digest: sha256:1e869e97892e5398d1b1e91beb9ddb69403ac9ba4b3b74d2940a0d37a2471dd4
====>> Spin up Environment
Build-agent version 1.0.16017-6bc91f58 (2019-09-23T16:08:17+0000)
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:'
Step failed
Task failed
Error: 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:'

ジョブ名のデフォルト値は"build"なので,異なる場合はジョブ名を付与する必要があった


$ circleci local execute --help | grep job
Run a job in a container on the local machine
      --job string            job to be executed (default "build")

$ circleci local execute --job test -c ci_local.yml

ちなみにこちらでも同様の結果が得られた.


$ circleci build --job test -c ci_local.yml

課題

下記のコマンドどちらでもジョブを実行することができたが,両者の違いまでは調べていない.


$ circleci build --job test -c ci_local.yml
$ circleci local execute --job test -c ci_local.yml

ヘルプの内容も同一だった.


$ circleci local execute -h
Run a job in a container on the local machine


Usage:
  circleci build [flags]

Flags:
      --branch string         Git branch
      --checkout-key string   Git Checkout key (default "~/.ssh/id_rsa")
  -c, --config string         config file (default ".circleci/config.yml")
  -e, --env -e VAR=VAL        Set environment variables, e.g. -e VAR=VAL
  -h, --help                  help for build
      --index int             node index of parallelism
      --job string            job to be executed (default "build")
      --node-total int        total number of parallel nodes (default 1)
      --repo-url string       Git Url
      --revision string       Git Revision
      --skip-checkout         use local path as-is (default true)
  -v, --volume strings        Volume bind-mounting

Global Flags:
      --host string    URL to your CircleCI host, also CIRCLECI_CLI_HOST (default "https://circleci.com")
      --token string   your token for using CircleCI, also CIRCLECI_CLI_TOKEN

参考

2
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
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?