firebase-tools
firebase-tools copied to clipboard
Function deploy fails to delete scheduled function without Cloud Scheduler job
[REQUIRED] Environment info
firebase-tools: 11.4.0
Platform: macOS
[REQUIRED] Test case
import * as functions from "firebase-functions";
export const v1scheduled = functions.pubsub.schedule("every 30 minutes").onRun(() => {});
[REQUIRED] Steps to reproduce
- Deploy a scheduled function
- Delete the Cloud Scheduler job associated w/ the scheduled function
- Try deleting the function via
firebase functions:delete <fn>
[REQUIRED] Expected behavior
Delete the pubsub topic and the function
[REQUIRED] Actual behavior
Command fails:
HTTP 404: Job not found
You have to go manually delete the function in Cloud console. This is annoying, especially if you are running something like firebase deploy --force to clean up old functions as it marks the entire deployment as failed.
any update about this? I experienced this today
any update on this? I'm having same problem when trying to remove old functions
same issue
I'm seeing this issue as well.
I'm using the atlassian/firebase-deploy:5.1.0 (https://bitbucket.org/atlassian/firebase-deploy/src/master/) BitBucket pipeline to deploy both functions and hosting.
The first time I tried running this pipeline after removing a function from source control, I realized the Google Cloud IAM Service Account associated with the KEY_FILE Pipeline variable was missing the cloudscheduler.jobs.delete permission. I saw this error: HTTP Error: 403, The principal (user or service account) lacks IAM permission "cloudscheduler.jobs.delete" for the resource
I added that permission and re-ran the pipeline.
The second pipeline execution failed with HTTP Error: 403, Cloud Pub/Sub API has not been used in project .... After this pipeline execution failure, the affected functions in Cloud Console appeared to be "partially deleted" - the trigger column no longer listed the CRON schedule:
Before:
After:
All subsequent pipeline execution attempts now fail with HTTP Error: 404, Job not found.
In troubleshooting this, I realized my service account role was missing a few permissions:
- pubsub.topics.delete
- cloudscheduler.jobs.delete
- cloudscheduler.jobs.get
- cloudscheduler.jobs.get
Also, the service account I'm using for deployment belongs to a different organization than the project being deployed, so I had to enable the Cloud Pub/Sub API on the organization to which the service account belongs in order to make the API call to delete the topic.
Whilst awaiting merge request approval and a proper release, I was able to patch this into my deployment pipeline so I can "delete" Cloud Functions in the pipeline:
patch /usr/local/lib/node_modules/firebase-tools/lib/deploy/functions/release/fabricator.js .build/firebase-fabricator.patch
where the contents of .build/firebase-fabricator.patch is:
--- original-fabricator.js 2024-10-04 13:26:09.743553600 -0400
+++ fabricator.js 2024-10-04 17:29:32.601762600 -0400
@@ -160,7 +160,24 @@
await this.setTrigger(update.endpoint);
}
async deleteEndpoint(endpoint) {
- await this.deleteTrigger(endpoint);
+ try {
+ await this.deleteTrigger(endpoint);
+ }
+ catch (err) {
+ if (err instanceof reporter.DeploymentError &&
+ err.op == "delete schedule" &&
+ err.original.message == "HTTP Error: 404, Job not found.") {
+ logger_1.logger.warn(`Trigger for ${endpoint.id} not found. Continuing to delete function.`);
+ }
+ else if (err instanceof reporter.DeploymentError &&
+ err.op == "delete topic" &&
+ err.message.startsWith("Failed to delete topic function")) {
+ logger_1.logger.warn(`Failed to delete topic function for ${endpoint.id}. Ensure the account has 'pubsub.topics.delete' permission. You may need to manually delete the topic. Continuing to delete function.`);
+ }
+ else {
+ throw err;
+ }
+ }
if (endpoint.platform === "gcfv1") {
await this.deleteV1Function(endpoint);
}
@mathu97 how does #7781 resolve this? That PR seems to only modify files to src/emulator/apphosting
@mathu97 how does #7781 resolve this? That PR seems to only modify files to
src/emulator/apphosting
that PR was linked by accident! Re-openning this issue.