Skip to main content
Version: 5.x

Variables From Commands

If the source is command, DevSpace will not ask the user a question and instead execute a command to determine the value of the variable.

images:
database:
image: "mysql:${MYSQL_VERSION}"
vars:
- name: MYSQL_VERSION
source: command
# Will execute the command in a Golang Shell (cross plattform compatible)
command: "echo 5.5"

If you need different commands depending on the operating system you can use commands:

images:
database:
image: "mysql:${MYSQL_VERSION}"
vars:
- name: MYSQL_VERSION
source: command
commands:
- command: bash
args: ["-c", "echo '5.5'"]
os: linux,darwin
command: echo
args: ["5.5"]
info

If not command for the current operating system can be found under commands, the command and args will be used as fallback.

Variable Type

By default, the type (string, int, bool) of variable will be determined by the type of its default value (if defined) or automatically detected if no default value is defined. To explicitly use the value of a variable as a string, use $!{VAR_NAME} instead of ${VAR_NAME}.

Configuration

name

The name option expects a string stating the name of the config variable that will be used to reference it within the remainder of the configuration.

Must be unique

The name of a config variable must be unique and is mandatory when defining a config variable.

command & args

The command and arguments to execute to retrieve the value of the variable. The captured stdout of the command will be used as variable value. Whitespaces and newlines will be trimmed from the command output.

tip

You can use other variables in the command or args definition as long as they are either a predefined variable or defined before the variable in the vars array. For example:

vars:
- name: SECRET_NAME
source: env
- name: SECRET_VALUE
command: ./retrieve-secret-value.sh
args: ["--secret-name=${SECRET_NAME}", "--namespace=${devspace.namespace}"]

commands

Commands expects an array of objects that define commands for specific operating systems. If no command can be found for the current operating system in commands, then command will be used as fallback.

vars:
- name: MYSQL_VERSION
source: command
commands:
# Use command on linux
- command: bash
args: ["-c", "echo '5.5'"]
os: linux
# Use command on mac
- command: bash
args: ["-c", "echo '5.6'"]
os: darwin
# Use on all other operating systems
command: echo
args: ["5.5"]

default

If the command returns nothing, this is the value that will be used for this variable.

alwaysResolve

If enabled, the variable will be loaded even though it is not used within the config. This might be useful for variables that should be resolved after a config expression is applied. E.g.:

devspace.yaml:

vars:
- name: my-var
value: my-value
alwaysResolve: true
hooks:
- name: my-hook
command: $(cat command.txt)
events: ["after:deploy"]

command.txt:

echo Hello ${my-var}!