【问题标题】:Vue deployment to Heroku with CircleCI failing: fatal: Not a git repository (or any of the parent directories): .gitVue 部署到 Heroku,CircleCI 失败:致命:不是 git 存储库(或任何父目录):.git
【发布时间】:2021-02-12 07:30:18
【问题描述】:

使用 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.js heroku circleci


    【解决方案1】:

    找出我缺少的东西。

    - 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 没有在看根目录,因此发现了我的问题。

    我花了几个小时才弄明白!!!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-12-23
      • 1970-01-01
      • 1970-01-01
      • 2012-08-11
      • 2021-12-12
      • 2012-09-03
      • 2017-02-08
      相关资源
      最近更新 更多