deploy cloud functions using cloud build failed: Error: failed to get firebase project

Viewed 63

=== Deploying to 'project_id'...

Step #1:

Step #1: I deploy functions

Step #1:

Step #1: Error: Failed to get Firebase project project_id. Please ensure the project exists and that your account has permission to access it.

This is the error I am getting when I try to deploy my cloud function using cloud build.

This is my cloudbuild.yaml steps:

#Install
- name: 'gcr.io/cloud-builders/npm'
  args: ['install']
  
#Deploy
- name: 'gcr.io/flysample-75b81/firebase'
  args: ['deploy']

And this is my package.json

{
  "name": "functions",
  "description": "Cloud Functions for Firebase",
  "scripts": {
    "serve": "firebase emulators:start --only functions",
    "shell": "firebase functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "engines": {
    "node": "16"
  },
  "main": "index.js",
  "dependencies": {
    "body-parser": "^1.20.0",
    "firebase-admin": "^10.0.2",
    "firebase-functions": "^3.18.0"
  },
  "devDependencies": {
    "firebase-functions-test": "^0.2.0"
  },
  "private": true
}

If anyone has an idea, Let me know how to solve this error.

1 Answers

As stated in the documentation,

Create a build config file named cloudbuild.yaml or cloudbuild.json where project-id is your Cloud project ID and firebase-project-id is your Firebase project ID

You should specify your Firebase Project ID in the .yaml or .json file. See sample below:

steps:
- name: gcr.io/project-id/firebase
  args: ['deploy', '--project=firebase-project-id', '--only=hosting']
Related