Skip to main content
In this lesson, you’ll learn how to pass variables from a caller workflow into a reusable workflow using workflow_call inputs. By declaring inputs explicitly, you avoid the common pitfall where environment variables defined at the caller level don’t automatically propagate.
Reusable workflows require GitHub Actions workflow_call. See the GitHub Actions Reusing Workflows guide for details.

The Problem: Empty Environment Variables

When you define environment variables in the caller workflow, they aren’t forwarded to the reusable workflow. For example, this secret creation command ran with an empty MONGO_URI:
Because MONGO_URI was never passed, the URI value remained blank:
The image shows a GitHub Docs page about GitHub Actions, specifically focusing on the limitations of reusable workflows. It includes a navigation menu on the left and detailed text about workflow limitations on the right.
To fix this, we define inputs in the reusable workflow and explicitly pass values from the caller.

Define an Input in the Reusable Workflow

Edit your reusable workflow (e.g. .github/workflows/reuse-deployment.yml) and add an inputs section under workflow_call. Here we declare a required string input mongodb-uri:
Notice how we replaced the hard-coded MONGO_URI with ${{ inputs.mongodb-uri }}.

Store the URI as a Repository Variable

In your repository settings under Settings › Actions › Variables, create a variable named mongo_uri:
The image shows a GitHub repository settings page focused on "Actions secrets and variables," displaying environment variables for different namespaces and replicas.
  • Name: mongo_uri
  • Value: mongodb+srv://supercluster.d8jjj.mongodb.net/superData
Repository variables are not encrypted. Use Secrets for sensitive values like passwords.

Call the Reusable Workflow with Inputs

In your caller workflow (e.g. .github/workflows/solar-system.yml), remove the old env: block for MongoDB and invoke the reusable workflow using a with block:
This ensures both development and production deployments receive the correct mongodb-uri.

Adding Dynamic Inputs

To make your reusable workflow more flexible, you can declare additional inputs—such as kubectl-version, k8s-manifest-dir, and environment. Update workflow_call like so:
Table: Reusable Workflow Inputs Reference these inputs in your job steps:
And in the caller workflow, pass all required inputs:
Keep input names consistent between caller and reusable workflows to minimize errors.

Verification in Workflow Run

When the workflow executes, you’ll see the passed inputs in the reusable job’s Inputs section:
The image shows a GitHub Actions workflow interface with a series of jobs and their statuses, including unit testing, code coverage, and deployment steps. The workflow is in a "Waiting" status, with some jobs completed and others in progress.
  • mongodb-uri, kubectl-version, k8s-manifest-dir, and environment are listed under Inputs.
  • The MongoDB secret is created with the correct URI.
  • Manifests are applied from the specified directory.
  • The deployment environment dynamically matches your input.

Next, we’ll explore how to propagate outputs from the reusable workflow back into the caller workflow for advanced chaining and reporting.

References

Watch Video