选一次 shell,必要时按步骤覆盖
工作流声明它的 shell,所有步骤继承它。未声明时 Dagu 依次优先 PowerShell、pwsh、cmd.exe,因此在一台机器上写好的工作流在另一台上的行为是可预期的。
- shell 接受字符串或数组;数组形式可以避免 -NoProfile 这类参数的引号问题
- 步骤可以把输出捕获到命名变量中,后续步骤和前置条件都能读取
- preconditions 用该值控制步骤,因此只有服务确实处于停止状态时才会重启
# service-health.yaml
schedule: "*/15 * * * *"
max_active_runs: 1
shell: powershell -NoProfile
steps:
- id: check_service
run: |
(Get-Service -Name 'MyAppSvc').Status
output: SVC_STATUS
- id: restart_if_stopped
run: Restart-Service -Name 'MyAppSvc'
depends: check_service
preconditions:
- condition: "${SVC_STATUS}"
expected: "Stopped"
retry_policy:
limit: 2
interval_sec: 30
mail_on:
failure: true