5
9

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 5 years have passed since last update.

[CircleCI] 特定のディレクトリに差分がなければ job を正常終了する

Last updated at Posted at 2019-06-22

差分チェックスクリプト

scripts/circleci/is_changed_directory.sh
#!/bin/bash
# See: https://blog.hatappi.me/entry/2018/10/08/232625

if [ "${CIRCLE_BRANCH}" = "master" ]; then
  DIFF_TARGET="HEAD^ HEAD"
else
  DIFF_TARGET="origin/master"
fi

DIFF_FILES=(`git diff ${DIFF_TARGET} --name-only --relative=${1}`)

if [ ${#DIFF_FILES[@]} -eq 0 ]; then
  exit 1
else
  exit 0
fi

.circleci/config.yml

..circleci/config.yml
script_setup: &script_setup
  command: |
    echo 'export PATH=$PATH:${CIRCLE_WORKING_DIRECTORY}/scripts/circleci' >> $BASH_ENV

jobs:
  sample_job:
    steps:
      - checkout
      - run:
          <<: *script_setup
      - run:
          name: 後続の job 実行継続判定
          command: |
            if ! is_changed_directory.sh "foo/bar" -a "${CIRCLE_BRANCH}" != "master"; then
              echo "foo/bar に変更がありません"
              circleci step halt
            fi

参考

5
9
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
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?