Skip to content

Hello World Example

This example demonstrates the core features of YAML Workflow: - Template task for generating text with variable substitution - Shell task for running commands and displaying information - Built-in variables (run_number, workflow_name, timestamp, workspace)

Workflow File

# A minimal example workflow that demonstrates core features:
# - Template task for generating text with variable substitution
# - Shell task for running commands and displaying information
# - Built-in variables (run_number, workflow_name, timestamp, workspace)
#
# Required parameters:
# - name: The name to include in the greeting (e.g., name=World)

name: Hello World
description: A simple workflow that creates a greeting

params:
  name:
    description: Name to include in the greeting
    default: World

steps:
  - name: create_greeting
    task: template
    template: |
      Hello, {{ name }}!

      This is run #{{ run_number }} of the {{ workflow_name }} workflow.
      Created at: {{ timestamp }}
      Workspace: {{ workspace }}
    output: greeting.txt

  - name: show_info
    task: shell
    command: |
      echo "Workflow run information:"
      echo "------------------------"
      echo "Run number: {{ run_number }}"
      echo "Workflow: {{ workflow_name }}"
      echo "Created: {{ timestamp }}"
      echo "Workspace: {{ workspace }}"
      echo "------------------------"
      echo "Current directory: $(pwd)"
      cat greeting.txt

Features Demonstrated

  1. Parameter Definition
  2. Defines a name parameter with a default value
  3. Uses parameter validation and description

  4. Template Task

  5. Creates a greeting using template substitution
  6. Demonstrates variable interpolation
  7. Shows output file creation

  8. Shell Task

  9. Runs shell commands
  10. Shows environment information
  11. Reads and displays files

  12. Built-in Variables

  13. run_number: Unique run identifier
  14. workflow_name: Name of the workflow
  15. timestamp: Current time
  16. workspace: Working directory

Usage

  1. Save the workflow:

    mkdir -p workflows
    cp examples/hello_world.yaml workflows/
    

  2. Run with default parameter:

    yaml-workflow run workflows/hello_world.yaml
    

  3. Run with custom name:

    yaml-workflow run workflows/hello_world.yaml name="Alice"
    

Expected Output

Workflow run information:
------------------------
Run number: 1
Workflow: Hello World
Created: 2024-01-23T10:30:00Z
Workspace: /path/to/workspace
------------------------
Current directory: /path/to/workspace
Hello, Alice!

This is run #1 of the Hello World workflow.
Created at: 2024-01-23T10:30:00Z
Workspace: /path/to/workspace