
CircleCIの「circleci-agent step halt」コマンドの動作を確認する
CircleCIには「circleci-agent step halt」のコマンドがあります。これは、Jobを途中で正常終了させるコマンドです(失敗扱いにならない)。
このコマンドの動作仕様が気になったので、実際に試してみました。
おすすめの方
- CircleCIの「circleci-agent step halt」コマンドの動作を知りたい方
- シンプルなCircleCIの設定ファイルを知りたい方
まずは、CircleCIを準備する
CircleCIの設定ファイルを作成する
mkdir .circleci
touch .circleci/config.yml
次の2つのJobを順番に実行します。
- unit-test
- deploy
version: 2.1
executors:
normal_container:
docker:
- image: cimg/node:lts
jobs:
unit-test:
executor: normal_container
steps:
- checkout
- run:
name: unit-test
command: |
echo "run unit-test"
deploy:
executor: normal_container
steps:
- run:
name: deploy
command: |
echo "run deploy"
workflows:
release:
jobs:
- unit-test
- deploy:
requires:
- unit-test
CircleCIでプロジェクトを設定する
無事に動きました。
「circleci-agent step halt」の動作を確認する
ひとつのrunの場合、処理は続く
「circleci-agent step halt」コマンドのあとに、echo・sleep・echoを実行してみます。
version: 2.1
executors:
normal_container:
docker:
- image: cimg/node:lts
jobs:
unit-test:
executor: normal_container
steps:
- checkout
- run:
name: unit-test
command: |
echo "run unit-test"
circleci-agent step halt
echo "running??"
sleep 10
echo "running????"
deploy:
executor: normal_container
steps:
- run:
name: deploy
command: |
echo "run deploy"
circleci-agent step halt
echo "running??"
sleep 10
echo "running????"
workflows:
release:
jobs:
- unit-test
- deploy:
requires:
- unit-test
「circleci-agent step halt」コマンドのあとのechoが実行されています。stepの実行時間が10秒なので、sleepも実行されています。
複数のrunの場合、後続のrunは実行されない
「circleci-agent step halt」コマンドのあとに、別の「run step」を追加してみました。
- unit-test-2
- deploy-2
version: 2.1
executors:
normal_container:
docker:
- image: cimg/node:lts
jobs:
unit-test:
executor: normal_container
steps:
- checkout
- run:
name: unit-test
command: |
echo "run unit-test"
circleci-agent step halt
echo "running??"
sleep 10
echo "running????"
- run:
name: unit-test-2
command: |
echo "run unit-test-2"
sleep 5
echo "running unit-test-2"
deploy:
executor: normal_container
steps:
- run:
name: deploy
command: |
echo "run deploy"
circleci-agent step halt
echo "running??"
sleep 10
echo "running????"
- run:
name: deploy-2
command: |
echo "run deploy-2"
sleep 5
echo "running deploy-2"
workflows:
release:
jobs:
- unit-test
- deploy:
requires:
- unit-test
「circleci-agent step halt」コマンドを実行したあとの「run step」は、実行されませんでした。
run以外のstepでも実行されない
run以外のstepをいくつか追加してみました。
version: 2.1
executors:
normal_container:
docker:
- image: cimg/node:lts
jobs:
unit-test:
executor: normal_container
steps:
- checkout
- run:
name: unit-test
command: |
echo "run unit-test"
circleci-agent step halt
echo "running??"
sleep 10
echo "running????"
- run:
name: unit-test-2
command: |
echo "run unit-test-2"
sleep 5
echo "running unit-test-2"
- checkout
- checkout
- restore_cache:
key: v1-myapp-cache
- save_cache:
key: v1-myapp-cache-new
paths:
- ~/d2
deploy:
executor: normal_container
steps:
- run:
name: deploy
command: |
echo "run deploy"
circleci-agent step halt
echo "running??"
sleep 10
echo "running????"
- run:
name: deploy-2
command: |
echo "run deploy-2"
sleep 5
echo "running deploy-2"
- checkout
- checkout
- restore_cache:
key: v1-myapp-cache
- save_cache:
key: v1-myapp-cache-new
paths:
- ~/d2
workflows:
release:
jobs:
- unit-test
- deploy:
requires:
- unit-test
結果として、「circleci-agent step halt」コマンドを実行したあとの「step」は、実行されませんでした。
さいごに
あくまでもJobを途中で正常終了させるだけです。ワークフロー的に次のJobが存在する場合は、次のJobの実行に移ります。
- ワークフローは、jobの集まり
- jobは、stepの集まり
地味なハマりポイントだと思いました。参考になれば幸いです。