Deploy to Firebase not working

Hi there!

I’m trying to set up a workflow for my React project. What I want to achieve is to get a job to build the stuff and another one to deploy the master branch to Firebase hosting.

This is what I have so far after several configurations:

version: 2
jobs:
  build:
    docker:
      - image: circleci/node:7.10
    working_directory: /tmp/myproject
    steps:
      - checkout
      - restore_cache:
          keys:
          - v1-dependencies-{{ checksum "package.json" }}
          - v1-dependencies-

      - run: yarn install

      - save_cache:
          paths:
            - node_modules
          key: v1-dependencies-{{ checksum "package.json" }}

      - run:
          name: Build app in production mode
          command: |
            yarn build
  deploy:
    docker:
      - image: circleci/node:7.10
    working_directory: /tmp/myproject
    steps:
      - run:
          name: Deploy Master to Firebase
          command: ./node_modules/.bin/firebase deploy --token=MYTOKEN

workflows:
  version: 2
  build-and-deploy:
    jobs:
      - build
      - deploy:
          requires:
            - build
          filters:
            branches:
              only: master

The build job always success, but with the deploy I have this error:

#!/bin/bash -eo pipefail 
./node_modules/.bin/firebase deploy --token=MYTOKEN 

/bin/bash: ./node_modules/.bin/firebase: No such file or directory 
Exited with code 1

So, what I understand is that the deploy job is not running in the same place the build was, right?

I’m not sure how to fix that. I’ve read some examples and tried several things, but it doesn’t work. I’ve also read the documentation but I think it’s not very clear how to configure everything… maybe I’m too dumb.

I hope you guys can help me out on this one.

Cheers!!

1 Like

Correct, they are always fresh machines.

I have not run into this problem myself, but I believe Workspaces can help you here. They are a device to declare a directory as restorable in a job from a prior job in the same Workflow. Take a peek in the manual!

1 Like

Hey @halfer. Thank you for your help and sorry for my delayed response.

I’ve been trying to get it working with Workspaces but I haven’t had any luck. And it is a real pain to have to commit and push every change to the configuration file to test it on CircleCI.

Not sure if you guys could help me… I’m out of ideas, I’ve tried a lot of things…
This is how my config file looks right now:

witmy: &witmy
  docker:
    - image: circleci/node:7.10
    
version: 2
jobs:
  build:
    <<: *witmy
    steps:
      - checkout
      - restore_cache:
          keys:
          - v1-dependencies-{{ checksum "package.json" }}
          - v1-dependencies-

      - run: yarn install

      - save_cache:
          paths:
            - node_modules
          key: v1-dependencies-{{ checksum "package.json" }}

      - run:
          name: Build app in production mode
          command: |
            yarn build

      - persist_to_workspace:
          root: .
  deploy:
    <<: *witmy
    steps:
      - attach_workspace:
          at: .

      - run:
          name: Deploy Master to Firebase
          command: ./node_modules/.bin/firebase deploy --token=MY_TOKEN

workflows:
  version: 2
  build-and-deploy:
    jobs:
      - build
      - deploy:
          requires:
            - build
          filters:
            branches:
              only: master

Right now I’m getting this error on CircleCI:

Persisting to Workspace
The specified paths did not match any files in /home/circleci/project

Cheers!

1 Like

I don’t have time to help presently, sorry - maybe in a couple of days. I wonder though whether your save/restore paths need to be absolute, not relative?

1 Like

No worries. When you have the time. I’ll keep trying.
I’ve tried paths in a lot of different ways, including absolute ones…
Thanks mate :slight_smile:

1 Like

A good way to be thorough about this is to make a list of the things you have tried, and then to try them all (again if needs be) so you can find out what error you get in each case.

I’d try these:

  • relative path, whole project (.)
  • relative path subfolder (./something)
  • absolute path, whole project (/app)
  • absolute path, subfolder (/app/something)

If you can try each of these, and let us know what you get for each, that’d be great. I’d lean towards absolute paths, personally; relative paths feel a bit flakey here.

I am assuming /app is the root checkout dir, so /home/circleci/project looks odd to me. I wonder if the default dir for checkout is /app but the default dir for workspaces is /home/circleci/project? If so, you need to fix one of them.

Yeah! What you can do here is to use a throwaway branch, so you can delete the mess it causes, once you’re done.

1 Like

Thanks a lot for your answer.

Now I got it working… not sure if in the best way possible, but it works.
Only thing I’ve done is to set the persist_to_workspace as:

- persist_to_workspace:
      root: .
      paths:
          - .

So I’m saving everything from my first job. Probably improvable, but now I have something working and I can start implementing improvements.

Thanks again :slight_smile:

2 Likes
- persist_to_workspace:
      root: .
      paths:
          - .

this is what did the trick for me! I spend 3 hours searching for and trying out solutions but finally this got it working, thanks!

2 Likes

Interesting, that looks like it might create a different data structure to @jvlobo’s one. If you are interested, you can see what data structure is produced by a piece of YAML here (this can also help with debugging YAML indentation generally). It can be a tricky format to work with.

1 Like

Sorry, I didn’t pay attention to the indentation of the quote.
I meant to say that what @jvlobo suggested worked for me as well.

1 Like

If it is wrong, please do fix that post! Readers here are in the habit of copying+pasting code/config they find, so we might as well try to leave behind a trail of working material if we can.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.