How to deploy some functions to Cloud Functions for Firebase without affecting some other functions?
Asked Answered
F

9

183

When I run

firebase deploy --only functions

it reads the index.js file and updates all functions exported from that file. If on the previous deploy there was a function named a, and in the current deploy there is no such function, a will be deleted.

In other words, the effect is the same as if all existing functions were deleted and then the all functions from the current index.js file were added.

Is it possible to add/update/delete individual functions?

Fantasist answered 13/4, 2017 at 8:1 Comment(0)
F
371

Firebase CLI tools 3.8.0 has added the ability to deploy specific functions.

firebase deploy --only functions:func1,functions:func2

--only <targets>     
only deploy to specified, comma-separated targets (e.g. "hosting,storage"). For functions, 
can specify filters with colons to scope function deploys to only those functions (e.g. "--only functions:func1,functions:func2"). 
When filtering based on export groups (the exported module object keys), use dots to specify group names 
(e.g. "--only functions:group1.subgroup1,functions:group2)"

Add surrounding quotes if needed:

firebase deploy --only "functions:func1,functions:func2"

Fantasist answered 16/5, 2017 at 10:28 Comment(5)
Is this still working? I get an error when I try this now, but it used to workJehovist
Please Note: do not put a Space after a comma firebase deploy --only functions:func1,functions:func2Musician
For now it seems it should be firebase deploy --only "functions:func1,functions:func2"Chilli
What about updating an internal helper function or variable? Impossible I guess...Flood
I have killed 1 hour to recognize why multiple deployment stops working. thank you @SergeyMell for mentioned quote escape.Barrios
M
90

The following way worked for me to deploy a particular function without affecting my other functions, where specificFunctionName is the function I wanted to deploy

firebase deploy --only functions:specificFunctionName

To copy the command quickly in terminal:

firebase deploy --only functions:
Maximomaximum answered 5/1, 2019 at 11:38 Comment(0)
U
12

I never managed to get it working (and have no codebase property in my firebase.json) until I tried what @Sergey Mell mentioned in his comment :

firebase deploy --only "functions:func1,functions:func2"

The surrounding double quotes was what solved the issue.

Undertook answered 20/10, 2022 at 13:57 Comment(0)
E
9

firebaser here

There is currently no way to deploy a single function with the Firebase CLI. Running `firebase deploy` will deploy all functions.

We've recently discussed deploying subsets of the functions, but it's not available at the moment - nor can we give a ballpark of if/when it might be.

Update Since Firebase CLI release the ability to deploy single functions is available. See yuku's answer.

Ebsen answered 13/4, 2017 at 8:23 Comment(1)
Currently not working for node ^14, for some reason running firebase deploy --only functions works fine, but firebase deploy --only functions:fetch_financials throws: package.json in functions directory has an engines field which is unsupported. Valid choices are: {"node": "8"}, {"node": "10"}, and {"node":"12"}. @FrankvanPuffelenFishwife
Z
7
firebase deploy --only "functions:<fileName>.<functionName>"

example folder structure:

functions 
  node_modules
  index.js
  smsNotification.js
  ...

You can redeploy just a function in a file with

firebase deploy --only "functions:smsNotification.sendChatNotif"

You can redploy all functions in a file with

firebase deploy --only "functions:smsNotification"
Zibeline answered 24/8, 2021 at 3:34 Comment(0)
J
5

In case anyone still can't make it work using firebase deploy --only functions:func1,functions:func2, it's probably because you're probably using codebases, "codebase": "my-codebase", in your firebase.json. Took me a while to diagnose but after removing that codebase property, deploying only some functions using the --only flag worked for me

Johnjohna answered 5/9, 2022 at 5:12 Comment(1)
Good point. I noticed that my codebase definition was off and reset it to "source": "functions", "codebase": "default",. Now, deployment for single functions works again.Venipuncture
F
2

As a complement: if you're using a codebase then you should add it before the function name:

firebase deploy --only functions:codebase_name:function_name

Fate answered 11/9, 2023 at 16:30 Comment(0)
R
0

This one gave me the missing package. Although package was included but I had to reinstall the mentioned package.

firebase --debug deploy --only functions:[functionName]

Royer answered 29/1, 2023 at 0:28 Comment(0)
O
0
$ firebase --version
12.7.0

Not works

firebase deploy --only functions:func1:func2
firebase deploy --only functions:func1,func2
firebase deploy --only functions:func1.func2
firebase deploy --only functions:[func1,func2]

Works

firebase deploy --only functions:func1,functions:func2
Oosperm answered 27/1, 2024 at 13:9 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.