CircleCIの「circleci-agent step halt」コマンドの動作を確認する

CircleCIの「circleci-agent step halt」コマンドの動作を確認する

「circleci-agent step halt」コマンドを実行したあとの「step」は、実行されませんでした。stepを分けましょう。
Clock Icon2025.06.04

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
.circleci/config.yml
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でプロジェクトを設定する

01_circleci_project_setup

無事に動きました。

02_circleci_workflow

「circleci-agent step halt」の動作を確認する

ひとつのrunの場合、処理は続く

「circleci-agent step halt」コマンドのあとに、echo・sleep・echoを実行してみます。

.circleci/config.yml

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も実行されています。

11_circleci_workflow

12_circleci_jobs

13_circleci_jobs

複数のrunの場合、後続のrunは実行されない

「circleci-agent step halt」コマンドのあとに、別の「run step」を追加してみました。

  • unit-test-2
  • deploy-2
.circleci/config.yml

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」は、実行されませんでした。

21_circleci_workflow

22_circleci_jobs

23_circleci_jobs

run以外のstepでも実行されない

run以外のstepをいくつか追加してみました。

.circleci/config.yml
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」は、実行されませんでした。

31_circleci_workflow

32_circleci_jobs

33_circleci_jobs

さいごに

あくまでもJobを途中で正常終了させるだけです。ワークフロー的に次のJobが存在する場合は、次のJobの実行に移ります。

  • ワークフローは、jobの集まり
  • jobは、stepの集まり

地味なハマりポイントだと思いました。参考になれば幸いです。

参考

Share this article

facebook logohatena logotwitter logo

© Classmethod, Inc. All rights reserved.