1
1

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コマンドを実行したとき、"git: not found"と表示され、エラーとなる

Posted at

概要

ローカルでcircleci buildコマンドを使って設定ファイルを確認しようとしたところ、エラーでタスクが正常終了しない。

console
====>> Checkout code
  #!/bin/sh -eo pipefail
mkdir -p /root/project && cd /tmp/_circleci_local_build_repo && git ls-files | tar -T - -c | tar -x -C /root/project && cp -a /tmp/_circleci_local_build_repo/.git /root/project
/bin/sh: git: not found
tar: empty archive
tar: short read
Error: Exited with code 1
Step failed
Error: runner failed (exited with 101)
Task failed
Error: task failed

実行したconfig.ymlは下記の通り。

config.yml
version: 2
jobs:
  build:
    docker:
      - image: node:12.13.0-alpine
    steps:
      - checkout
      - run:
          name: Greeting
          command: echo Hello, world.
      - run:
          name: Print the Current Time
          command: date

原因

コンソールにも出力されているように、checkout時、コンテナ上でgitが実行できないことが原因。
今回使用しているimage:node:12.13.0-alpineには
gitはデフォルトでは入っていない。

対応

checkout実行前に、apkコマンドでgitを用意してあげる。

config.yml
version: 2
jobs:
  build:
    docker:
      - image: node:12.13.0-alpine
    steps:
      - run:
          name: add git
          command: apk -U add git
      - checkout
      - run:
          name: Greeting
          command: echo Hello, world.
      - run:
          name: Print the Current Time
          command: date

実行結果は以下の通り

console
====>> Checkout code
  #!/bin/sh -eo pipefail
mkdir -p /root/project && cd /tmp/_circleci_local_build_repo && git ls-files | tar -T - -c | tar -x -C /root/project && cp -a /tmp/_circleci_local_build_repo/.git /root/project
====>> Greeting
  #!/bin/sh -eo pipefail
echo Hello, world.
Hello, world.
====>> Print the Current Time
  #!/bin/sh -eo pipefail
date
Sun Dec  1 12:48:31 UTC 2019
Success!

無事、実行されました。

1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?