# Create Workflow

Source: https://docs.ops0.com/docs/workflows/create-workflow

Build automated workflows using the visual DAG (Directed Acyclic Graph) builder.

## Workflow Editor

Left Panel

Step palette - drag steps onto canvas

Canvas

Visual DAG builder - arrange and connect steps

Right Panel

Step configuration - settings for selected step

Header

Name, Save, Run, Settings buttons

---

## Building a Workflow

### Adding Steps

1. **Drag & Drop** - Drag a step from the left panel onto the canvas

2. **Connect** - Click output port (right) and drag to input port (left) of next step

3. **Configure** - Click a step to open its settings in the right panel

4. **Save** - Click Save (draft) or Save & Activate (enabled)

### Step Palette

| Category | Steps |
|----------|-------|
| **Infrastructure** | IaC Deploy, Configuration Deploy |
| **Actions** | Script, HTTP Request |
| **Flow Control** | Approval, Wait, Condition, Loop |
| **Notifications** | Email, Slack, Webhook |

---

## Workflow Settings

| Setting | Description |
|---------|-------------|
| **Timeout** | Max execution time for entire workflow |
| **Concurrency** | Allow multiple runs simultaneously |
| **Failure Action** | Stop all, continue, or retry failed steps |
| **Notifications** | Email/Slack on success or failure |

---

## Variables

Reference variables in step configurations using `${...}` syntax.

| Variable | Description |
|----------|-------------|
| `${workflow.name}` | Workflow name |
| `${workflow.run_id}` | Current execution ID |
| `${trigger.type}` | How workflow was triggered |
| `${trigger.branch}` | Git branch (if git trigger) |
| `${steps.step_name.output}` | Output from a previous step |
| `${env.VARIABLE}` | Environment variable |

---

## Parallel Steps

Connect one step to multiple next steps to run them in parallel.

```
              ┌─────────┐
        ┌────▶│ Step B  │────┐
┌───────┤     └─────────┘    │     ┌─────────┐
│ Step A│                    ├────▶│ Step D  │
└───────┤     ┌─────────┐    │     └─────────┘
        └────▶│ Step C  │────┘
              └─────────┘
```

- Steps B and C run simultaneously
- Step D waits for both to complete

---

## Validation

The editor validates your workflow before saving:

| Error | Description |
|-------|-------------|
| **Disconnected step** | Step has no connections |
| **Cycle detected** | Circular dependency found |
| **Missing config** | Required field is empty |
| **Invalid reference** | Variable doesn't exist |

---

## Example: Creating a Deploy Pipeline

### Step 1: Create Workflow

```
Click: Workflows → + Create Workflow
Name:  api-deploy-pipeline
```

### Step 2: Add Steps

Drag these steps onto the canvas and connect them:

| Order | Step Type | Name |
|-------|-----------|------|
| 1 | IaC Deploy | Plan Infrastructure |
| 2 | Approval | Production Approval |
| 3 | IaC Deploy | Apply Infrastructure |
| 4 | HTTP Request | Health Check |
| 5 | Slack | Notify Team |

### Step 3: Configure Each Step

**Plan Infrastructure:**
```
Project:  api-infrastructure
Action:   Plan
```

**Production Approval:**
```
Approvers:     team:platform-team
Message:       Please review the Terraform plan
Timeout:       2 hours
```

**Apply Infrastructure:**
```
Project:  api-infrastructure
Action:   Apply
```

**Health Check:**
```
URL:           https://api.example.com/health
Method:        GET
Success Codes: 200
Retry:         3 times
```

**Notify Team:**
```
Channel:  #deployments
Message:  ✅ API deployment complete
          Changes: ${steps.apply.output.summary}
```

### Step 4: Configure Trigger

```
Settings → Triggers → Git Push
Repository:    acme/api-infrastructure
Branch:        main
Path Filter:   terraform/**
```

### Step 5: Save & Activate

```
Click: Save & Activate
Status: Active ✓
```

### Result

```
Workflow: api-deploy-pipeline
─────────────────────────────────────
Status:     Active
Trigger:    Git Push (main)
Steps:      5
Created:    Just now
```
