5

I have created a group of Firebase Cloud Functions (v2) that are deployed in a region (europe-west1).

#index.ts
import * as apiV2 from './v2';
export const v2 = apiV2;
#v2.ts
export const addTextMessage = functions.region('europe-west1').onCall(
 ...
)

I want only to deploy the addTextMessage function. I tried:

firebase deploy --only functions:v2-addTextMessage
# or
firebase deploy --only "functions:v2-addTextMessage(europe-west1)"

However the function is not deployed:

✔  functions: functions folder uploaded successfully
i  functions: current functions in project: v2-addTextMessage(europe-west1)
⚠  functions: the following filters were specified but do not match any functions in the project: v2-addTextMessage(europe-west1)

What command should I use?

windycrazy
  • 63
  • 5

2 Answers2

5

Try to replace the "-" by ".".

You should use :

firebase deploy --only functions:groupName.functionName

In your case :

firebase deploy --only functions:v2.addTextMessage

It's true that the CLI terminal log is misleading because if you've exceeded your deployment quota and the CLI detects that the name of your function is for instance v2-addTextMessage(europe-west-1), it will print a message suggesting you to use the command firebase deploy --only functions:v2-addTextMessage to deploy this function only, which doesn't work.

See the full Firebase CLI documentation here

musiquarc
  • 91
  • 2
1

You are using the correct command, however, you have not exported the addTextMessage function to your index.ts file, without that the deployment cannot find the funtion to deploy. You can export it by adding the following code to your index.ts:

export const v2-addTextMessage = apiV2.addTextMessage

Also, you cannot use the functions parameter and the function name as a String. So your command on this case would have to be:

firebase deploy --only functions:v2-addTextMessage

For Specifying region on deployment, as you already added to your code on the edited version of the question, you cannot do it on the FirebaseCLI command, thanks to @Doug Stevenson for pointing that out on the comment section.

Ideally, as you can see on this video, you would have to specify that in your cloud function code, before deployment by adding the following:

exports.v2-addTextMessage = functions
    .region('europe-west1')
    .storage.object().onFinalize((object) => { });
Ralemos
  • 5,571
  • 2
  • 9
  • 18
  • 1
    Deployment doesn't have a `--region` flag. That's just for deleting a function in a specific region that was deployed to multiple regions. https://firebase.google.com/docs/cli – Doug Stevenson Apr 21 '20 at 17:00
  • @Doug Stevenson Thanks, I will edit that part out of the answer, I was looking at this [gcloud documentation](https://cloud.google.com/sdk/gcloud/reference/functions/deploy) and assumed it was also applicable for FirebaseCLI. – Ralemos Apr 22 '20 at 10:16
  • This command does not work either. To be more accurate, the function is not called `v2-addTextMessage`. The function is `addTextMessage` is declared in a `v2.ts `file : (` export const addTextMessage = functions.region('europe-west1').onCall( ....) `. And the global ìndex.ts` contains: `import * as apiV2 from './api/apiV2'; export const v2 = apiV2; – windycrazy Apr 22 '20 at 15:36
  • So does `firebase deploy --only functions:addTextMessage` not work? Not sure what you meant by index is export, can you clarify? – Ralemos Apr 22 '20 at 15:40
  • My comment is not clear, I have edited the question to show the organization of my functions. – windycrazy Apr 22 '20 at 15:44
  • @windycrazy replace this line `export const v2 = apiV2;` by this `export const addTextMessage = apiV2.addTextMessage`, or simply add it if you need it somewhere else in your code. Then try to deploy using `firebase deploy --only functions:addTextMessage` and let me know if it works – Ralemos Apr 22 '20 at 16:13
  • @ralemos yes it works fine like this. However I would really like to have the v2 group. – windycrazy Apr 23 '20 at 19:47
  • What do you mean by have the v2 group? Deploy the whole group or have the "v2" in the command? You can do the latter it by adding `v2-` to the `export const` mentioned above. Anyway, I will edit the answer to reflect the command above that you confirmed it work, please consider accepting and upvoting the answer if it sufficiently helped you. – Ralemos Apr 24 '20 at 12:48
  • @windycrazy Is this what you expected? If so, remember to accept the answer and upvote it. – Ralemos Apr 28 '20 at 11:38
  • @ralemos Sorry it doesn't work. `const v2-addTextMessage` is not valid javascript. – windycrazy Apr 28 '20 at 12:08
  • what if you lose the `-` on the variable name? – Ralemos Apr 28 '20 at 12:13