is it possible run 2 garden commands sequentially ...
# 🤖|ask-kapa
a
@microscopic-river-74022 is it possible run 2 garden commands sequentially using a 1 custom command (https://docs.garden.io/features/custom-commands). I would like to run cleanup deploy and cleanup namespace as an optional custom command. I tried something like this and it does not work:
Copy code
kind: Command
name: cleanup-all
description:
  short: Cleans up all environments (preview in the current project configuration)
gardenCommand:
  - cleanup
  - deploy
  - app,app2
  - "&&"
  - cleanup
  - namespace
The other option might be to create 2 custom commands and then call that command (similar to a Makefile target), but this would require 3 custom commands. I am trying to avoid that.
m
Please stand by @ancient-island-74119 as I search the knowledge base. I normally take about 15 seconds or so. :wave:
---------------------- Short answer: not directly with a single custom command. - A Command’s gardenCommand is a single Garden CLI invocation expressed as an array; it does not support shell operators like && or chaining multiple Garden commands in one list. Only exec and gardenCommand are templatable, and gardenCommand should start with one command name followed by its flags/args ([Custom Commands overview]()). - Your example includes "&&" between commands, which won’t work because gardenCommand isn’t a shell; it’s just argv for one Garden command ([Custom Commands]()). Workarounds based on the docs: - Use exec to run a shell that invokes two Garden commands sequentially:
Copy code
kind: Command
  name: cleanup-all
  description:
    short: Cleans up deploys and then the namespace
  exec:
    command:
      - sh
      - -c
      - |
        garden cleanup deploy app,app2 && garden cleanup namespace
This leverages the allowed exec step before any gardenCommand ([Custom Commands]()). - Alternatively, define a Workflow with two command steps, which runs multiple Garden commands in sequence and is generally more efficient than scripting separate CLI calls:
Copy code
kind: Workflow
  name: cleanup-all
  steps:
    - command: [cleanup, deploy, app,app2]
    - command: [cleanup, namespace]
Then run with garden workflow cleanup-all ([Workflows]()).
Reference for the commands you mentioned: garden cleanup deploy supports names like app,app2 and relevant options ([garden cleanup deploy]()). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
message has been deleted
2 Views