Pick the shell once, or per step
A workflow declares its shell and every step inherits it. Without one, Dagu prefers PowerShell, then pwsh, then cmd.exe, so a workflow written on one machine behaves predictably on another.
- The shell accepts a string or an array; the array form avoids quoting problems with arguments like -NoProfile.
- A step captures its output into a named variable, which later steps and preconditions can read.
- Preconditions gate a step on that value, so a restart only happens when the service is actually stopped.
# service-health.yaml
schedule: "*/15 * * * *"
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