LoginSignup
5
4

More than 5 years have passed since last update.

CircleCIでジョブを途中で終了する

Posted at

任意のタイミングでジョブを終了する方法は、run:circleci step halt を実行することです。

なぜこんなものが必要かというと、masterにタグがpushされたときだけ処理したいような場合があります。
しかしこんなふうにfiltersを設定しても、masterにプッシュされただけで、タグが無くてもreleaseジョブは実行されてしまいます。

config.yml
workflows:
  version: 2
  release:
    jobs:
      - release:
          filters:
            branches:
              only:
                - master
            tags:
              only:
                - /^.*$/

そこでreleaseジョブの中で、タグが設定されていなかったら後続の処理をしないでスキップしたいという発想になりました。
以下のようなジョブ定義で意図した動作になりました。

config.yml
jobs:
  release:
    <<: *job_base
    steps:
      - run:
          name: skip_if_no_tag
          command: |
            if [ "${CIRCLE_TAG}" == "" ]; then
              echo "no tag"
              circleci step halt
            fi
      - checkout
      - run: bundler install
      - <<: *restore_gradle_cache
      - <<: *resolve_gradle
      - <<: *save_gradle_cache
      - run: fastlane deploy
5
4
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
5
4