Skip to content

Cloud Functions Deployment: CI/CD, Versioning, Environment Config & Monitoring

DodaTech Updated 2026-06-28 5 min read

In this tutorial, you will learn about Cloud Functions Deployment: CI/CD, Versioning, Environment Config & Monitoring. We cover key concepts, practical examples, and best practices to help you master this topic.

Deploying Cloud Functions requires managing configurations, environment variables, CI/CD pipelines, monitoring, and rollback strategies — moving from development to production reliably.

What You'll Learn

How to deploy Cloud Functions, configure environments, automate with GitHub Actions, monitor function performance, manage versions, and roll back failed deployments.

Why It Matters

Manual deployments are error-prone and slow. An automated pipeline catches issues early and provides audit trails. DodaTech deploys 30+ functions across dev, staging, and production with zero-downtime through CI/CD.

Real-World Use

A developer pushes a change to a Cloud Function that processes threat scans. The CI pipeline runs tests, deploys to staging, runs integration tests, then promotes to production — all automatically.

flowchart LR
    A["Git Push\nMain Branch"] --> B["GitHub Actions\nCI Pipeline"]
    B --> C["Run Unit Tests"]
    C --> D["Deploy to\nStaging"]
    D --> E["Integration\nTests"]
    E --> F{"Pass?"}
    F -->|No| G["Notify Team\nFix Issues"]
    F -->|Yes| H["Deploy to\nProduction"]
    H --> I["Monitor\nLogs + Alerts"]
    style A fill:#dbeafe,stroke:#2563eb
    style D fill:#fef3c7,stroke:#d97706
    style H fill:#bbf7d0,stroke:#16a34a

Basic Deployment

# Deploy all functions
firebase deploy --only functions

# Deploy a specific function
firebase deploy --only functions:registerDevice

# Deploy functions in a specific region
firebase deploy --only functions:us-central1-registerDevice

# Deploy with function group
firebase deploy --only functions:groupName

Expected output:

=== Deploying to 'durga-antivirus-pro'...
i  deploying functions
i  functions: creating function registerDevice...
✔  functions[registerDevice]: Successful create operation.
✔  Deploy complete!

Environment Configuration

// Set environment configs
// firebase functions:config:set env.name="production" alerts.email="ops@dodatech.com"

// Access in functions
const envName = functions.config().env.name;
const alertEmail = functions.config().alerts.email;

exports.checkConfig = functions.https.onCall((data, context) => {
  console.log("Environment:", envName);
  console.log("Alert email:", alertEmail);
  return { env: envName };
});

Use .env files for local development:

# .env.local
ENV_NAME=development
ALERT_EMAIL=dev@dodatech.com
SAMPLE_RATE=0.1

CI/CD with GitHub Actions

# .github/workflows/deploy-functions.yml
name: Deploy Cloud Functions

on:
  push:
    branches: [main]
    paths:
      - "functions/**"
      - "firebase.json"

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - uses: actions/setup-node@v4
        with:
          node-version: "20"
          cache: "npm"
          cache-dependency-path: functions/package-lock.json

      - name: Install dependencies
        run: npm ci
        working-directory: functions

      - name: Run lint and tests
        run: |
          npm run lint
          npm test
        working-directory: functions

      - name: Deploy to Firebase
        uses: FirebaseExtended/action-hosting-deploy@v0
        with:
          repoToken: ${{ secrets.GITHUB_TOKEN }}
          firebaseServiceAccount: ${{ secrets.FIREBASE_SERVICE_ACCOUNT }}
          channelId: live
          projectId: durga-antivirus-pro

Expected CI output:

Running lint... ✔
Running tests... ✔ (12/12 passing)
Deploying functions...
✔  functions[registerDevice]: Successful create operation.
✔  functions[analyzeFile]: Successful update operation.
✔  Deploy complete!

Monitoring and Alerts

// Add structured logging for better monitoring
exports.processScan = functions.firestore
  .document("scans/{scanId}")
  .onCreate(async (snap, context) => {
    console.log("Processing scan", {
      scanId: context.params.scanId,
      userId: snap.data().userId,
      severity: snap.data().severity
    });

    try {
      // Function logic here
      console.log("Scan processed successfully");
    } catch (error) {
      console.error("Scan processing failed", {
        scanId: context.params.scanId,
        error: error.message
      });
      // Send alert
      await sendErrorAlert(error, context.params.scanId);
    }
  });

Monitor in Google Cloud Console:

# View function logs
firebase functions:log

# Tail logs in real-time
firebase functions:log --tail

# Filter by function name
firebase functions:log --only processScan

Versioning and Rollbacks

# View deployment history
firebase functions:list

# Roll back a function to a previous version
# (re-deploy the previous version from git)

# Use Cloud Run revisions (for 2nd gen functions)
# in Google Cloud Console > Cloud Run > Revisions

# For quick rollback: re-deploy the previous working code
git checkout HEAD~1 -- functions/
firebase deploy --only functions:processScan
git checkout main -- functions/

Common Mistakes

1. Hardcoding Environment Variables

Environment-specific values (API keys, URLs) should never be in source code. Use functions.config() or Secret Manager.

2. Deploying Without Running Tests

Deploying untested functions risks breaking production. Always run unit tests and integration tests in CI before deployment.

3. Ignoring Region Selection

Functions deployed in us-central1 have different latency for users in other regions. Deploy functions close to your users using functions.region().

4. Not Setting Memory and Timeout

Default 256MB memory and 60s timeout may not suit all workloads. Configure appropriately: functions.runWith({ memory: "1GB", timeoutSeconds: 300 }).

5. Overwriting Configs Across Environments

Running <a href="/apis/firebase/">Firebase</a> deploy --only functions deploys all functions and uses the current project's config. Use separate Firebase projects for dev, staging, and prod.

Practice Questions

  1. How do you deploy only a single function?
  2. How do you manage environment-specific configuration?
  3. What steps should a CI/CD pipeline include for functions?
  4. How do you monitor function errors in production?

Answers:

  1. Use firebase deploy --only functions:functionName to deploy a single function.
  2. Use functions.config() to store environment variables. Set them per-project using firebase functions:config:set.
  3. Lint, unit tests, deploy to staging, integration tests, deploy to production, smoke tests.
  4. Use Cloud Logging (console.log), set up error reporting with Sentry, and configure Cloud Monitoring alerts for failure rates.

Challenge: Set up a CI/CD pipeline for a functions project: GitHub Actions that runs on push to main, installs deps, runs lint and tests, deploys to Firebase staging project, runs integration tests, and promotes to production.

FAQ

Can I deploy functions without downtime?

Yes. Cloud Functions uses gradual rollout for updates. Existing requests finish with the old version while new requests use the updated version.

How do I store secrets for Cloud Functions?

Use Google Cloud Secret Manager. Access secrets via process.env.SECRET_NAME after binding the secret to the function.

What is the difference between 1st gen and 2nd gen functions?

2nd gen functions run on Cloud Run, support longer timeouts (60 min), larger instances (up to 32GB), and concurrency. 1st gen is simpler but more limited.

Can I deploy functions from multiple source directories?

Yes, use firebase.json to specify multiple source directories under functions.source configuration.

How do I set up a staging environment?

Create a separate Firebase project for staging. Use firebase use staging to switch projects before deploying.

Mini Project

Create a deployment pipeline: configure environment variables for dev/staging/prod, write a CI workflow (lint, test, deploy), add error monitoring with structured logging, and implement a rollback procedure for failed deployments.

What's Next

Firebase Hosting Deep Dive — deploy web apps with CDN, custom domains, and Serverless functions.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro