首页 > 解决方案 > Vue 部署到 Heroku,CircleCI 失败:致命:不是 git 存储库(或任何父目录):.git

问题描述

使用 CircleCI 部署到 HEROKU 时遇到问题。我已经测试过git push heroku master手动部署到heroku,这是有效的。但是,当我使用 CircleCI 时,部署不再有效。

Github 仓库地址:https ://github.com/dulerong/vue-test-circleci

我在 CircleCI 项目设置中设置了 HEROKU 环境变量。

HEROKU_API_KEY=my_key
HEROKU_APP_NAME=my_app_name

错误信息如下。

#!/bin/bash -eo pipefail
if false;then
  force="-f"
fi

heroku_url="https://heroku:$HEROKU_API_KEY@git.heroku.com/$HEROKU_APP_NAME.git"

if [ -n "$CIRCLE_BRANCH" ]; then
  git push $force $heroku_url $CIRCLE_BRANCH:main
elif [ -n "$CIRCLE_TAG" ]; then
  git push $force $heroku_url $CIRCLE_TAG^{}:main
else
  echo "No branch or tag found."
  exit 1
fi
fatal: Not a git repository (or any of the parent directories): .git

Exited with code exit status 128
CircleCI received exit code 128

下面是我的 circleCI config.yml

version: 2.1
orbs:
  heroku: circleci/heroku@1.2.5
jobs:
  build-job:
    working_directory: ~/repo
    docker:
      - image: circleci/node:12.18.2
    steps:
      - checkout
      - run: 
          name: Install dependencies
          command: npm install
      - run: 
          name: Build
          command: npm run build
      - save_cache:
          key: dependency-cache-{{ checksum "package-lock.json" }}
          paths:
            - ./node_modules
      - run:
          name: lint
          command: npm run lint
      - run:
          name: test
          command: npm run test:unit

  deploy-job:
    working_directory: ~/repo
    docker: 
      - image: circleci/node:12.18.2
    steps:
      - attach_workspace:
          at: ~/repo
      - heroku/deploy-via-git

workflows:
  version: 2.1
  deploy:
    jobs:
      - build-job
      - deploy-job:
          requires:
            - build-job
          filters:
            branches:
              only: master

  1. 我已将 CircleCI 链接到我的 Github 存储库
  2. 我创造了.circleci folder config.yml
  3. 我在 heroku 上创建了一个应用程序,当我手动部署时它可以工作
  4. 我的 CircleCI 的构建部分有效,但是部署不起作用

任何帮助表示赞赏,在此先感谢。

标签: vue.jsherokucircleci

解决方案


发现我错过了什么。

- checkout

我在部署工作中缺少这行代码。因此,在将 deploy-job yml 配置代码更改为以下之后,一切正常。

deploy-job:
    working_directory: ~/repo
    docker: 
      - image: circleci/node:12.18.2
    steps:
      - checkout<--- INSERT THIS CODE HERE!!!!
      - attach_workspace:
          at: ~/repo
      - heroku/deploy-via-git

原因:checkout命令将 CircleCI 引导到项目的根目录。因此,如果没有这行代码,您将看到一个甚至不是项目根目录的文件夹目录。

其他有用的命令包括

      - run:
          name: show directory 
          command: pwd
      - run:
          name: look in directory
          command: ls -ltr

如果您将这些命令放在下方checkouk,并查看您的 CircleCI 项目中的工作进度,您实际上可以看到 CircleCI 正在查看哪个目录,在那一刻,对于检查 CircleCI 正在哪个目录工作非常有用。我把这两个命令并发现我的 CircleCI 没有查看根目录,因此发现了我的问题。

我花了几个小时才弄清楚这个!


推荐阅读