You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Why it is bad: the `cd /srv/app` line becomes part of every block, including remote blocks.
116
116
117
-
## 4. Assume every block runs in a fresh shell
117
+
## 4. Use block directives for timeout, retry, and exports
118
+
119
+
Block directives must appear immediately after the `# @LOCAL` or `# @REMOTE <host>` marker, before any command lines. They configure execution behavior for that specific block.
120
+
121
+
### Timeout Directive
122
+
123
+
`# @TIMEOUT <seconds>` - Abort the block if it exceeds the specified duration.
124
+
125
+
```bash
126
+
# @LOCAL
127
+
# @TIMEOUT 30
128
+
sleep 60
129
+
```
130
+
131
+
### Retry Directive
132
+
133
+
`# @RETRY <count>` - Retry the block up to N times on failure (0 means no retry).
134
+
135
+
```bash
136
+
# @LOCAL
137
+
# @RETRY 3
138
+
curl -f https://api.example.com/health
139
+
```
140
+
141
+
### Export Directive
142
+
143
+
`# @EXPORT NAME=source` - Capture a value from the block result and pass it to subsequent blocks as an environment variable.
Why it is bad: `artifact` and the working directory do not persist.
160
213
161
-
## 5. Use SHELLFLOW_LAST_OUTPUT for explicit handoff
214
+
## 6. Use SHELLFLOW_LAST_OUTPUT for explicit handoff
162
215
163
216
Shellflow passes the previous block's combined output into the next block as `SHELLFLOW_LAST_OUTPUT`.
164
217
@@ -197,7 +250,7 @@ print(payload["release"])
197
250
PY
198
251
```
199
252
200
-
## 6. Use SSH config host aliases, not ad-hoc targets
253
+
## 7. Use SSH config host aliases, not ad-hoc targets
201
254
202
255
`# @REMOTE <ssh-host>` should point to a host that resolves through SSH config.
203
256
@@ -210,7 +263,7 @@ Avoid assuming Shellflow accepts any arbitrary free-form destination unless it i
210
263
211
264
If a remote host is unknown, Shellflow fails before execution.
212
265
213
-
## 7. Keep blocks self-contained and fail-fast
266
+
## 8. Keep blocks self-contained and fail-fast
214
267
215
268
Shellflow runs blocks in order and stops on the first failure.
216
269
@@ -243,17 +296,69 @@ docker compose up -d
243
296
244
297
Why: the second block cannot rely on the first block's `cd`.
245
298
299
+
## 9. CLI Options and Output Modes
300
+
301
+
Shellflow provides several CLI options for different use cases:
302
+
303
+
### Basic Options
304
+
305
+
```bash
306
+
shellflow run script.sh # Run a script
307
+
shellflow run script.sh -v # Run with verbose output
308
+
shellflow run script.sh --dry-run # Preview execution plan without running
309
+
```
310
+
311
+
### Structured Output
312
+
313
+
```bash
314
+
shellflow run script.sh --json # Single JSON report
315
+
shellflow run script.sh --jsonl # Streaming JSON Lines events
316
+
```
317
+
318
+
-`--json`: Outputs a single JSON object with the complete run report
319
+
-`--jsonl`: Outputs one JSON object per event (run_started, block_started, block_finished, run_finished)
320
+
321
+
### Execution Control
322
+
323
+
```bash
324
+
shellflow run script.sh --no-input # Non-interactive mode (stdin closed)
325
+
shellflow run script.sh --ssh-config /path/to/config # Custom SSH config
326
+
```
327
+
328
+
-`--no-input`: Closes stdin before running blocks; useful for automation
329
+
-`--ssh-config`: Override the default SSH config path (`~/.ssh/config`)
330
+
331
+
### Audit Logging
332
+
333
+
```bash
334
+
shellflow run script.sh --audit-log audit.jsonl --jsonl
335
+
```
336
+
337
+
The `--audit-log` option writes redacted JSON Lines events to a file. Secret-like exports (containing TOKEN, SECRET, or PASSWORD in the name) are automatically redacted to `[REDACTED]`.
338
+
339
+
## 10. Exit Codes
340
+
341
+
Shellflow returns distinct exit codes for different failure types:
342
+
343
+
-`0`: Success
344
+
-`1`: General execution failure
345
+
-`2`: Parse failure (invalid script syntax)
346
+
-`3`: SSH config failure (host not found)
347
+
-`4`: Timeout failure (block exceeded timeout)
348
+
246
349
## Authoring Checklist
247
350
248
351
Before returning a Shellflow playbook, verify that:
249
352
250
353
- The script is valid bash without custom DSL syntax.
251
-
- Only `# @LOCAL` and `# @REMOTE <host>` are used.
354
+
- Only `# @LOCAL`, `# @REMOTE <host>`, and block directives (`# @TIMEOUT`, `# @RETRY`, `# @EXPORT`) are used.
355
+
- Block directives appear immediately after the block marker, before any commands.
252
356
- Anything before the first marker is safe to repeat for every block.
253
357
- Every block can run independently in a fresh shell.
254
-
- Cross-block data uses `SHELLFLOW_LAST_OUTPUT` explicitly.
358
+
- Cross-block data uses `SHELLFLOW_LAST_OUTPUT`or `@EXPORT`explicitly.
255
359
- Remote targets match the intended SSH host aliases.
256
360
- Commands that should happen once are not accidentally placed in the shared prelude.
361
+
- Export sources are valid (stdout, stderr, output, exit_code).
0 commit comments