Custom Commands
The idea of custom commands is that someone on a team defines a set of useful commands and stores them in the devspace.yaml
, then commits and pushes this config to the code repository. Now, others can run these custom commands without having to remember all the details or having to read through endless pages of documentation.
Custom commands are being shared in the commands
section of devspace.yaml
:
# File: devspace.yaml
images:
default:
image: john/backend
commands:
debug-backend: |-
devspace dev $@
Custom commands can be used for more than just running devspace
commands, e.g. they can run any other script or command, set environment variables etc. If you are familiar with the scripts
section of the package.json
for Node.js, you will find that devspace run [name]
works pretty much the same way as npm run [name]
The above example configuration would allow everyone to run the custom command debug-backend
like this:
devspace run debug-backend
devspace run debug-backend -n my-namespace
And devspace run
would execute the following commands internally:
devspace dev
devspace dev -n my-namespace
--
End of Options SeparatorThe --
between the command name and the additional flags for the command tells your terminal that the arguments and flags that follow after the --
do not belong to devspace run
and should not be parsed. It is not required but often helpful to use --
when executing commands using devspace run
.
Custom commands proxy input and output streams, so you can even share interactive commands such as devspace enter
.
Configuration
commands
required <command_name>:object
Commands are custom commands that can be executed via 'devspace run COMMAND'. These commands are run within a pseudo bash
that also allows executing special commands such as run_watch or is_equal.
commands
required <command_name>:object <command_name>
required string
Name is the name of a command that is used via devspace run NAME
<command_name>
required string devspace run NAME
section
required string
Section can be used to group similar commands together in devspace list commands
section
required string devspace list commands
command
required string
Command is the command that should be executed. For example: 'echo 123'
command
required string args
required string[]
Args are optional and if defined, command is not executed within a shell
and rather directly.
args
required string[] appendArgs
required boolean false
AppendArgs will append arguments passed to the DevSpace command automatically to
the specified command.
appendArgs
required boolean false description
required string
Description describes what the command is doing and can be seen in devspace list commands
description
required string devspace list commands
internal
required boolean false
Internal commands are not show in list and are usable through run_command
internal
required boolean false after
required string
After is executed after the command was run. It is executed also when
the command was interrupted which will set the env variable COMMAND_INTERRUPT
to true as well as when the command errored which will set the error string to
COMMAND_ERROR.
after
required string Useful Commands
devspace list commands
Run this command to list all custom commands that are configured:
devspace list commands
devspace run dependency1.command
You can run a command defined in one of the dependencies of the current project like this:
devspace run [dependency].[command] [command-flags-and-args]
When running a command of a dependency, DevSpace will use the root folder of the dependency as current working directory when executing the command.