The introduction of the workflow_dispatch event has fundamentally transformed GitHub Actions from a purely reactive automation engine—triggered by pushes or pull requests—into a powerful, interactive platform for operational orchestration. By enabling manual triggers, GitHub provides developers and DevOps engineers with the ability to execute specific logic on demand, transforming static YAML definitions into flexible, parameterized tools. This capability is surfaced within the GitHub User Interface through a dedicated "Run workflow" button on the Actions tab, granting users a level of control that was previously only available through complex API calls or external scheduling tools.
The core utility of workflow_dispatch lies in its ability to accept inputs. These inputs are not merely variables; they are dynamically generated form elements in the GitHub UI that allow a human operator to specify the context of the run. Whether it is selecting a deployment environment, specifying a version tag, or toggling a "dry run" flag, the event allows for a bridge between human decision-making and automated execution. This architectural shift allows teams to move away from "hard-coded" workflow files and instead create generic "runbooks" that can be adapted to different scenarios based on the input provided at the moment of execution.
Fundamental Mechanics of the workflow_dispatch Event
The workflow_dispatch event is defined within the on section of a GitHub Actions YAML file. When this trigger is active, GitHub recognizes that the workflow is eligible for manual invocation.
yaml
on:
workflow_dispatch:
When a user navigates to the Actions tab in their repository, GitHub identifies all workflows configured with this event and displays a "Run workflow" button. A critical feature of this manual trigger is the ability to select the Git reference (branch, tag, or commit SHA) upon which the workflow should execute. This ensures that an operator can test a new version of a deployment script on a feature branch before promoting it to the main branch.
The integration of inputs further extends this functionality. Inputs are defined using a format consistent with action inputs, meaning they include a description, a requirement flag, and often a default value. These specifications are translated by GitHub into UI elements. For example, a boolean type becomes a checkbox, while a choice type becomes a dropdown menu.
yaml
on:
workflow_dispatch:
inputs:
logLevel:
description: 'Log level'
required: true
default: 'warning'
tags:
description: 'Test scenario tags'
The data provided by the user during the trigger process is injected into the github.event context. To access these values within a job, the workflow references the github.event.inputs object.
yaml
jobs:
printInputs:
runs-on: ubuntu-latest
steps:
- run: |
echo "Log level: ${{ github.event.inputs.logLevel }}"
echo "Tags: ${{ github.event.inputs.tags }}"
Advanced Input Types and Parameterization
To turn a workflow into a professional-grade tool, GitHub supports several distinct input types that dictate how the user interacts with the trigger form.
String Inputs
The string input is the most common type, used for capturing free-form text such as version numbers, commit SHAs, or custom tags.
yaml
inputs:
tag:
description: 'Release tag'
required: true
type: string
default: 'v1.0.0'
Choice Inputs
Choice inputs restrict the user to a predefined set of options, which is essential for maintaining data integrity and preventing typos in critical fields like environment names. This is rendered as a dropdown menu in the UI.
yaml
inputs:
log_level:
description: 'Log verbosity'
required: true
type: choice
options:
- debug
- info
- warning
- error
default: 'info'
Boolean Inputs
Boolean inputs are used for binary toggles, such as enabling a "dry run" mode or deciding whether to skip a specific set of tests.
yaml
inputs:
skip_tests:
description: 'Skip test execution'
required: false
type: boolean
default: false
Environment Inputs
The environment type is specifically designed to map the workflow trigger to a GitHub environment, allowing for the use of environment-specific secrets and variables.
yaml
inputs:
target_env:
description: 'Target environment'
required: true
type: environment
Strategic Implementation: The Operational Runbook Example
The true power of workflow_dispatch is realized when it is used to create operational runbooks. A runbook is a set of automated procedures used for system maintenance, disaster recovery, or administrative tasks.
In a complex maintenance scenario, a workflow can be designed to handle multiple distinct tasks—such as clearing caches or scaling services—within a single YAML file. To ensure safety, a "confirmation" input can be implemented, requiring the operator to type a specific string (e.g., "CONFIRM") to proceed.
```yaml
name: Maintenance
on:
workflow_dispatch:
inputs:
task:
description: 'Maintenance task'
required: true
type: choice
options:
- clear-cache
- restart-services
- run-migrations
- scale-down
- scale-up
environment:
description: 'Target environment'
required: true
type: environment
confirm:
description: 'Type CONFIRM to proceed'
required: true
type: string
jobs:
validate:
runs-on: ubuntu-latest
steps:
- name: Require confirmation
if: inputs.confirm != 'CONFIRM'
run: |
echo "Error: You must type CONFIRM to proceed"
exit 1
execute:
needs: validate
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}
steps:
- uses: actions/checkout@v4
- name: Clear cache
if: inputs.task == 'clear-cache'
run: ./scripts/clear-cache.sh
- name: Restart services
if: inputs.task == 'restart-services'
run: ./scripts/restart-services.sh
- name: Run migrations
if: inputs.task == 'run-migrations'
run: ./scripts/run-migrations.sh
- name: Scale down
if: inputs.task == 'scale-down'
run: ./scripts/scale.sh down
- name: Scale up
if: inputs.task == 'scale-up'
run: ./scripts/scale.sh up
```
This structure ensures a fail-safe mechanism where the execute job depends on the validate job. If the user fails to provide the correct confirmation string, the workflow terminates immediately, preventing accidental execution of destructive maintenance tasks.
Chaining Workflows and Programmatic Triggering
While the UI is the primary interface for workflow_dispatch, these workflows can also be triggered programmatically, enabling the chaining of separate CI and CD processes. This allows a build workflow to trigger a deployment workflow upon completion.
Using the GitHub API
A workflow can be triggered via a POST request to the GitHub API. This is useful for external systems or custom dashboards that need to kick off a GitHub Action.
bash
curl -X POST \
-H "Authorization: token $GITHUB_TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/owner/repo/actions/workflows/deploy.yml/dispatches \
-d '{
"ref": "main",
"inputs": {
"environment": "staging",
"version": "v1.2.3",
"dry_run": "false"
}
}'
Using the GitHub CLI
For developers working in the terminal, the GitHub CLI provides a streamlined way to trigger these parameterized workflows.
bash
gh workflow run deploy.yml \
-f environment=staging \
-f version=v1.2.3 \
-f dry_run=false
Chaining via GitHub Script
Within a workflow, the actions/github-script action can be used to trigger another workflow programmatically. This is a common pattern for separating the Build (CI) and Deploy (CD) phases.
yaml
- name: Trigger deploy
if: inputs.trigger_deploy
uses: actions/github-script@v7
with:
script: |
await github.rest.actions.createWorkflowDispatch({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: 'deploy.yml',
ref: 'main',
inputs: {
environment: '${{ inputs.target_environment }}',
version: '${{ github.sha }}'
}
});
Third-Party Orchestration: The benc-uk/workflow-dispatch Action
For more complex orchestration needs, such as triggering workflows in different repositories or waiting for a triggered workflow to complete, third-party actions like benc-uk/workflow-dispatch are utilized.
This action simulates a manual trigger. While the GitHub UI will report these runs as "manually triggered," they are actually initiated by another workflow. This tool is particularly valuable because it provides the run ID and URL of the triggered workflow, allowing the calling workflow to poll for status.
Implementation Configurations
The following table details the configuration options available when using the benc-uk/workflow-dispatch action.
| Parameter | Requirement | Description |
|---|---|---|
workflow |
Required | The name, filename, or ID of the workflow to trigger (e.g., My Workflow, my-workflow.yaml, or 1218419). |
inputs |
Optional | A JSON encoded string of inputs, e.g., { "message": "hello" }. |
ref |
Optional | The Git reference (branch, tag, SHA). Defaults to the triggering workflow's ref. |
repo |
Optional | The target repository in owner/repo format (e.g., microsoft/vscode). |
token |
Required (for external repos) | A PAT or token generated from a GitHub App/CLI. |
wait-for-completion |
Optional | If true, the action fails if the triggered workflow fails. Default: false. |
timeout-seconds |
Optional | Max time to wait for completion. Default: 900 seconds. |
Practical Usage Examples
Invoking a workflow without inputs:
yaml
- name: Invoke workflow without inputs
uses: benc-uk/workflow-dispatch@v1
with:
workflow: My Workflow
Invoking a workflow with inputs and waiting for the result:
yaml
- name: Invoke workflow with inputs & wait
uses: benc-uk/workflow-dispatch@v1
with:
workflow: Another Workflow
inputs: '{ "message": "blah blah", "something": true }'
wait-for-completion: true
Invoking a workflow in a separate repository:
yaml
- name: Invoke workflow in another repo with inputs
uses: benc-uk/workflow-dispatch@v1
with:
workflow: my-workflow.yaml
repo: benc-uk/example
inputs: '{ "message": "blah blah", "something": false }'
token: '${{ secrets.MY_TOKEN }}'
Comparative Analysis: workflow_dispatch vs. Reusable Workflows
GitHub has introduced "reusable workflows" as a native way to chain logic. It is important to distinguish this from the workflow_dispatch pattern.
workflow_dispatch is designed for external, manual, or programmatic triggers where a human or an API decides when the process starts. It focuses on the "trigger" mechanism.
Reusable workflows, conversely, focus on the "definition" mechanism. They allow a workflow to be called by another workflow as if it were a local job. While workflow_dispatch simulates a manual trigger (making it appear as "manually triggered" in the UI), reusable workflows are integrated more deeply into the execution graph of the caller.
Detailed Analysis of Triggering Logic and Outputs
When using programmatic dispatchers, specifically the benc-uk/workflow-dispatch action, the ability to capture outputs is a critical requirement for advanced DevOps pipelines. The action provides specific outputs that can be used in subsequent steps of the calling workflow.
runId: This is the unique identifier of the triggered workflow run. It is essential for any process that needs to track the lifecycle of the child workflow.runUrl: The API URL of the triggered run, used for programmatic queries.runUrlHtml: The browser-accessible URL, which can be posted to a Slack channel or a Jira ticket for visibility.workflowId: The unique ID of the workflow definition that was triggered.
The impact of these outputs is significant; without them, a calling workflow would be "fire and forget," meaning it would have no way of knowing if the downstream deployment actually succeeded or failed unless it was configured to wait for completion. By combining wait-for-completion: true with the runId output, engineers can create a synchronous chain of events across multiple repositories, effectively building a distributed orchestration system.
Final Conclusion
The workflow_dispatch event transforms GitHub Actions from a simple CI tool into a sophisticated operational platform. By utilizing parameterized inputs—ranging from simple strings to complex choice menus and environment selectors—teams can build highly flexible runbooks that handle everything from routine cache clearing to high-stakes production deployments. The ability to trigger these workflows via the GitHub UI, the REST API, or the GitHub CLI ensures that the automation is accessible to both human operators and other automated systems.
While native reusable workflows provide a method for sharing logic, workflow_dispatch remains the gold standard for manual intervention and cross-repository triggering. When augmented with tools like benc-uk/workflow-dispatch, the capability to wait for completion and capture run metadata allows for the construction of complex, multi-stage deployment pipelines that maintain strict separation between build and release phases. The implementation of confirmation checks and environment-specific inputs further ensures that these powerful tools are used safely and predictably in professional production environments.