workflow: Steps

REAL

workflow is a list. Each item is one step: a named unit that runs one tool and then says where to go next.

workflow:
  - step: start
    desc: Build a greeting
    tool:
      kind: rhai
      code: |
        "{{ workload.greeting }}, {{ workload.who }}"
    next:
      - step: shout
  - step: shout
    tool:
      kind: rhai
      code: |
        "{{ workload.greeting }}, {{ workload.who }}!".to_upper()

Step keys

These are all the keys a step has in the grammar at server v3.161.2 (Step in orchestrate-core/src/playbook.rs, and the Step type in Appendix A).

KeyRequiredWhat it isCovered in
stepyesThe step's name. It must be unique within the playbook; next targets refer to it.here
toolyes (server)What the step runs: one tool, or an ordered list of toolsChapter 5
descA descriptionhere
nextWhere control goes after the step: one name, a list, or a router of arcs with when guards6.1
whenAn enable guard: an expression checked before the step runs6.2
loopRun the step once per item of a collection6.3
specStep behaviour: next_mode, timeout, on_error6.5
argsInput arguments for the step5.3
varsValues to extract from the step's result into variables5.3
setVariable mutations applied when the step completes5.3

Two rules from the server's validator apply to the list as a whole (validate_playbook, src/playbook/parser.rs, server v3.161.2):

  • One step must be named start. The server begins every execution there, wherever it sits in the list.
  • Step names are unique, and every name used in a next must exist.

There is no special end step to declare. A step with no next simply ends its branch. Chapter 6 explains when the whole execution counts as finished.

Where the local runtime differs

Checked in CLI v6.4.1 (src/playbook_runner.rs):

  • It starts at the first step in the list, not at start. You can change that with --target <step>.
  • tool is optional. A step without one runs nothing and just routes.
  • It still runs the old case: blocks, which the server refuses.

Write playbooks for the server's rules (a start step, a tool on every step, no case:) and both runtimes accept their structure. A tool's own fields can still differ between the two; Chapter 5 shows where.

Step order is not run order

The position of a step in workflow decides nothing except, locally, which step runs first. Run order comes from next. This playbook lists done before start. It is still valid, and on a server it runs start and then done:

# Chapter 4.3: list position is not run order. The server starts at `start`;
# the local runtime (CLI 6.4.1) starts at the first step in the list.
apiVersion: noetl.io/v2
kind: Playbook
metadata:
  name: step_order
workflow:
  - step: done
    tool:
      kind: rhai
      code: |
        "done"
  - step: start
    tool:
      kind: rhai
      code: |
        "start"
    next:
      - step: done

The local runtime runs it differently. It starts at the first step in the list, done, which has no next, so the run ends there and start never runs. The book's CI checks exactly that (examples/ch04/step-order):

{
  "executed_steps": [
    "done"
  ],
  "final_result": "done",
  "playbook_name": "step_order",
  "status": "ok",
  "step_results": {
    "done": "done"
  }
}

Check your understanding