Workflow Dispatch Inputs

Earn 25 points (50 with Pro) in two steps

  1. ① Read through the lesson — each section gets a ✓ as you scroll through it.
  2. ② When every section has a ✓, tap Complete lesson.

0 of 12 read · keep scrolling

✦ See fewer ads and earn double points — 50 a lesson instead of 25 — with Pro

Workflow Dispatch Inputs: Mastering Manual Execution Control

Introduction: Why Manual Dispatch Matters

In the world of automated software delivery and infrastructure management, we often focus heavily on triggers that happen automatically—like a developer pushing code to a repository or a pull request being opened. However, there are many scenarios where you need the ability to trigger a process manually, or "on-demand." This is where workflow dispatch inputs come into play.

Workflow dispatch inputs allow you to create dynamic, interactive pipelines that accept parameters at the moment of execution. Instead of hardcoding values or relying solely on environmental variables, you provide a mechanism for users to supply specific data—such as version numbers, environment names, or feature flags—whenever they choose to run the workflow. This capability transforms static automation scripts into flexible tools that can adapt to the specific needs of a deployment or maintenance task.

Understanding how to configure these inputs is essential for any engineer looking to build self-service platforms. By empowering team members to trigger workflows safely with controlled inputs, you reduce the burden on DevOps engineers and decrease the time it takes to perform routine tasks. This lesson explores the technical implementation, configuration strategies, and best practices for managing these dispatch inputs effectively.


Not read yet

Understanding the Mechanics of Dispatch Inputs

At its core, a workflow dispatch input is a key-value pair defined in the configuration of your automation platform. When a user initiates a manual run, the system prompts them to provide values for these keys. These values are then injected into the workflow execution context, where they can be accessed by shell scripts, container actions, or conditional logic blocks.

Most modern CI/CD systems, such as GitHub Actions, GitLab CI, or Jenkins, provide a standardized way to define these inputs. You typically declare them in the workflow configuration file using a specific schema that identifies the input name, a description, the data type (string, boolean, choice, etc.), and whether the input is required.

The Anatomy of an Input Definition

To define an input, you generally need to provide four pieces of information:

  1. The Identifier (Key): The variable name you will use to reference the value later in your script.
  2. The Display Name/Label: A human-readable string that appears in the UI when the user clicks "Run Workflow."
  3. The Data Type: This dictates how the UI renders the input field (e.g., a text box, a dropdown menu, or a checkbox).
  4. Validation Rules: Constraints such as default values or lists of allowed options to ensure the workflow receives valid data.

Callout: The Philosophy of "Shift-Left" Control Workflow dispatch inputs are a fundamental component of the "Shift-Left" movement. By providing a safe, pre-configured interface for manual tasks, you move the control of complex operations—like database migrations or environment rollbacks—into the hands of the developers who own the code, while maintaining the safety rails provided by your automation platform.


Not read yet

Configuring Inputs: A Step-by-Step Guide

Let’s look at how to implement these inputs in a practical scenario. We will use a standard configuration format that is common across most YAML-based automation tools.

Step 1: Defining the Workflow Trigger

The first step is to enable the workflow_dispatch trigger. Without this, your workflow will only run on automated events (like push or pull requests). You must explicitly add this block to your configuration file.

on:
  workflow_dispatch:
    inputs:
      environment:
        description: 'The target environment for deployment'
        required: true
        default: 'staging'
        type: choice
        options:
          - staging
          - production
      version_tag:
        description: 'The semantic version to deploy'
        required: true
        type: string

Step 2: Accessing Inputs in Your Logic

Once the inputs are defined, they become available within the workflow environment. In most systems, these are accessed through an environment variable or a context object. You must map these inputs to environment variables or pass them directly into your steps to use them.

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Run Deployment Script
        run: ./deploy.sh
        env:
          TARGET_ENV: ${{ github.event.inputs.environment }}
          VERSION: ${{ github.event.inputs.version_tag }}

Step 3: Validating and Sanitizing Input

Never assume that the input provided by a user is safe or correct. Even with dropdown menus, you should perform validation inside your script. For example, if a user provides a version_tag, your script should verify that the tag exists in your container registry before attempting a deployment.

Note: Always treat user-provided inputs as untrusted data. Even if you use a dropdown menu in the UI, a malicious actor or an automated bot could potentially send a POST request to your workflow API with an arbitrary value that bypasses your UI constraints. Always validate inputs at the entry point of your script.


Not read yet

Best Practices for Workflow Dispatch Inputs

Building robust workflows requires a disciplined approach to how you handle inputs. If you create too many inputs, the UI becomes cluttered and confusing. If you create too few, the workflow lacks the necessary flexibility.

1. Keep Inputs Minimal

A workflow should do one thing well. If you find yourself adding ten or fifteen inputs to a single workflow, it is a sign that the workflow is doing too much. Consider breaking the workflow into smaller, specialized tasks that each accept only a few specific inputs.

2. Provide Sensible Defaults

Whenever possible, provide a default value that represents the most common use case. This reduces the cognitive load on the user and speeds up the execution process. If the user just needs to deploy to staging, they shouldn't have to type "staging" into a box every single time.

3. Use Descriptive Labels and Descriptions

The user interface for triggering a workflow is often the only documentation the end user will see. Use clear, descriptive labels for your inputs. Instead of a label like env, use Target Deployment Environment. Use the description field to provide context, such as instructions on the expected format of the input.

4. Implement Dropdowns for Restricted Values

Whenever an input has a finite set of valid options (like environments, regions, or service names), use a dropdown/choice type. This prevents typos and invalid entries that would otherwise cause your workflow to fail halfway through execution.

5. Version Control Your Input Definitions

Since your input configuration is part of your code, it is version-controlled. This is a massive advantage. If you change the input requirements, the change is tracked in Git, allowing you to audit who changed the input schema and why.


Not read yet

Comparison of Input Types

Understanding which input type to use for specific scenarios is key to building a great user experience.

Input Type Best Use Case UI Representation
String Free-form data like version tags, commit hashes, or custom flags. Text input field
Choice Selecting from a predefined list of environments, regions, or log levels. Dropdown menu
Boolean Toggling optional features (e.g., "Run database migrations?", "Skip tests?"). Checkbox
Environment Selecting a specific environment configuration defined in the platform. Pre-populated selector

Common Pitfalls and How to Avoid Them

Even experienced engineers fall into traps when designing interactive workflows. Here are the most common mistakes and how to navigate around them.

Pitfall 1: Over-reliance on Manual Inputs

If your team is constantly triggering a manual workflow for the same set of tasks, consider whether that process should be fully automated. If a task happens every time code is merged, it shouldn't be a manual dispatch; it should be an automated trigger. Manual dispatch is for exceptions, not for routine.

Pitfall 2: Lack of Input Sanitization

As mentioned earlier, failing to validate inputs is a security risk. If your input is a string and you pass it directly into a shell command, you are vulnerable to command injection. Always wrap inputs in quotes and use tools like shellcheck or built-in script validation to ensure the input contains only expected characters (e.g., alphanumeric and hyphens only).

Pitfall 3: Hidden Dependencies

Sometimes, an input change might require a corresponding change in a downstream system. If you change an input from environment to region, ensure that your deployment scripts or configuration files are updated simultaneously. A failure to synchronize these updates will result in broken workflows.

Warning: Be extremely careful when using inputs in shell commands. A user could input something like ; rm -rf / ; if you are concatenating strings directly into a command. Use environment variables to pass data into your scripts rather than building command strings via interpolation.


Not read yet

Practical Examples: Real-World Scenarios

To solidify your understanding, let’s look at three practical scenarios where workflow dispatch inputs are commonly used.

Scenario A: The "Force-Deploy" Workflow

Sometimes, you need to deploy a specific version of an application that might be older than the current one (e.g., for a rollback). You can create a workflow that accepts a version number and a force flag.

inputs:
  version:
    description: 'Version to deploy'
    required: true
  force_deploy:
    description: 'Bypass health checks'
    type: boolean
    default: false

In your script, you can then check the force_deploy variable:

if [ "$FORCE_DEPLOY" = "true" ]; then
  echo "Executing deployment without health checks..."
  ./deploy.sh --force --version "$VERSION"
else
  echo "Executing standard deployment..."
  ./deploy.sh --version "$VERSION"
fi

Scenario B: Dynamic Environment Provisioning

If your team uses Infrastructure as Code (IaC), you might have a workflow that provisions a new environment for testing. The inputs could include the environment name, the size of the instance, and the duration of the lease.

inputs:
  environment_name:
    description: 'Name of the test environment'
    required: true
  instance_type:
    description: 'Size of the server'
    type: choice
    options:
      - small
      - medium
      - large

This allows developers to spin up exactly what they need for a specific test without needing to ask a sysadmin to provision resources manually.

Scenario C: Database Maintenance

Database operations are high-risk. A manual dispatch workflow is the perfect place to require an "approval" style input. You can require a confirmation string, such as typing "CONFIRM" into an input field, before the workflow proceeds to run a destructive script.

inputs:
  confirmation:
    description: 'Type CONFIRM to proceed with migration'
    required: true

Inside your job, you can add a simple check:

if [ "$CONFIRMATION" != "CONFIRM" ]; then
  echo "Operation aborted: Confirmation string not provided."
  exit 1
fi

Not read yet

Advanced Configuration: Handling Complex Data

While simple strings and booleans cover 90% of use cases, sometimes you need to handle more complex data. If your platform supports it, you might be able to pass JSON strings as inputs.

Passing JSON as an Input

If you need to pass a complex configuration object, define the input as a string and parse it inside your workflow logic using a tool like jq.

inputs:
  config_json:
    description: 'JSON object for custom config'
    required: false

In your script:

echo "$CONFIG_JSON" | jq . > config.json
# Now you have a valid JSON file to use in your application

This is a powerful pattern for power users who need to provide granular overrides for complex deployment configurations. However, keep in mind that this is harder for typical users to interact with, so provide clear documentation on the expected JSON schema.


Integration with External APIs

Workflow dispatch inputs are not just for internal scripts. They are frequently used to trigger external processes. For instance, you might have a workflow that uses an input value to call an external API (like Jira, PagerDuty, or a Cloud Provider API).

Consider a workflow that updates a Jira ticket status. The input would be the ticket_id and the new_status.

steps:
  - name: Update Jira
    run: |
      curl -X POST -H "Authorization: Bearer $TOKEN" \
      -d '{"status": "'$NEW_STATUS'"}' \
      "https://api.jira.com/issue/$TICKET_ID/transitions"

This demonstrates the true power of dispatch inputs: they act as a bridge between your CI/CD platform and the rest of your organization's toolchain.


Not read yet

Security Considerations: The Human Element

When you enable manual dispatch, you are essentially granting "execute" permissions to whoever has access to the repository. It is vital to manage who can trigger these workflows.

Access Control

Most CI/CD platforms allow you to restrict who can trigger manual workflows based on repository permissions. Ensure that your organization’s security policy aligns with the access level required for the workflow. For example, a "Production Deploy" workflow should only be triggerable by users with "Write" or "Admin" access to the repository.

Audit Logging

Everything that happens in a manual workflow is logged. Use this to your advantage. If a production environment goes down, the first thing you should check is the workflow logs. The logs will show exactly who triggered the workflow, what inputs they provided, and what the outcome was.

Callout: The "Configuration as Code" Advantage Because your workflow inputs are defined in your repository, you get the benefit of "Configuration as Code." This means you can use Pull Requests to propose changes to the inputs. If someone wants to add a new option to a dropdown, they have to submit a PR, which can be reviewed by the team. This prevents "configuration drift" and ensures that changes to your automated processes are vetted.


Not read yet

Troubleshooting Workflow Dispatch

When things go wrong, the feedback loop for manual workflows can be frustrating. Here are the steps to debug effectively:

  1. Verify the Trigger: Ensure that the workflow_dispatch block is present in the default branch of your repository. If you are testing in a feature branch, make sure your CI/CD platform supports triggering workflows from branches other than the main branch.
  2. Check for Syntax Errors: YAML is notoriously sensitive to indentation. Use a linter to check your configuration file.
  3. Debug the Input Values: If your script is failing, add a step at the beginning of your job to print the input values.
    echo "The input value is: $INPUT_NAME"
    
    This simple step will tell you immediately if the value is being passed correctly or if it is coming through as empty.
  4. Examine Platform-Specific Limitations: Some platforms have limits on the number of inputs allowed or the total length of the input string. Check your platform’s documentation if you are hitting unexpected errors.

Not read yet

Summary of Best Practices

To wrap up, here is a quick reference guide to keep your workflows clean, safe, and efficient:

  • Minimalism: Only include inputs that are absolutely necessary. If a value can be derived automatically, don't ask the user for it.
  • Validation: Always validate inputs for type, length, and content before using them in any command.
  • Documentation: Use the description field to help users understand what each input does and what format is expected.
  • Defaults: Always provide defaults for non-critical inputs to make the workflow easier to use.
  • Security: Treat all inputs as untrusted. Use environment variables to pass data into scripts to prevent injection attacks.
  • Testing: Test your workflows in a development branch before merging them to the main branch.
  • Consistency: Use consistent naming conventions for your inputs (e.g., snake_case or kebab-case) across all your workflows.

Not read yet

Frequently Asked Questions (FAQ)

Can I change the input options dynamically?

In most standard CI/CD platforms, the input options (for a choice type) are static and defined in the YAML file. You cannot currently fetch them dynamically from an API at the moment the user clicks "Run." If you need dynamic options, you may need to build a custom UI or use a platform-specific plugin.

Can I have an input that is hidden from the UI?

No, the purpose of a workflow dispatch input is to be visible to the user. If you have sensitive information (like API keys or passwords), do not use inputs. Use your platform's "Secrets" or "Variables" management system instead.

What happens if I rename an input?

Renaming an input in your YAML file is a breaking change. If you have automated systems or other developers who rely on a specific API call to trigger that workflow, they will need to update their payload to match the new name. Always communicate such changes clearly.

Can I trigger a manual workflow from another workflow?

Yes, most platforms provide a way to trigger one workflow from another. When doing so, you can pass the inputs as a JSON object in the trigger call. This is a great way to chain workflows together.


Not read yet

Conclusion: Empowering Teams Through Automation

Workflow dispatch inputs are a small but powerful feature that can significantly improve the agility of your engineering team. By moving away from static, "all-or-nothing" automation, you can create systems that are responsive to the unique needs of every situation.

When you design these workflows, remember that you are designing a user interface for your colleagues. The best workflows are those that are intuitive, safe, and well-documented. By following the best practices outlined in this lesson—focusing on validation, sensible defaults, and clear communication—you can turn your CI/CD platform into a self-service engine that accelerates your development lifecycle.

As you continue to build and manage your workflows, look for opportunities to replace manual processes with these interactive triggers. Whether it's a simple toggle for a feature flag or a comprehensive set of parameters for a complex deployment, the ability to dispatch workflows on demand is a hallmark of a mature, high-performing engineering organization. Start small, iterate often, and always prioritize the safety and clarity of your automation.

Not read yet

Each section gets a ✓ as you scroll through it. Tap the button to jump to the next one.