Skip to main content
Version: 5.x

Input-based Variables

If source: all (default) | input, DevSpace may ask the user a question to determine the value of a config variable.

images:
database:
image: "mysql:${MYSQL_VERSION}"
vars:
- name: MYSQL_VERSION
question: Which mysql version do you want to use?
default: "5.7"
Ignore Env Variables

If you want DevSpace to ignore environment variables, you can explicitly define source: input to make sure only explict user input will be used to set the value of the variable.

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.

default

The default option expects a string, integer or boolean defining the default value for the variable. You can also use other variables in a default value, with one of the following conditions being true:

  • The used variable is defined before the variable that wants to use it
  • The used variable is a predefined variable
Type Casting

If a default value is specified, DevSpace will assume the type of the default value as the type for the variable, i.e. when default: "123" is defined and a value of 123 (int) is provided it would be casted to "123" (string). To explicitly use the value of a variable as a string within devspace.yaml, use $!{VAR_NAME} instead of ${VAR_NAME}.

Example:

images:
default:
image: ${IMAGE}
vars:
- name: IMAGE_REPOSITORY
default: myrepository
source: none
- name: IMAGE_NAME
default: devspace
source: none
- name: IMAGE
default: ${IMAGE_REPOSITORY}/${IMAGE_NAME}
source: none
- name: NAMESPACE
default: ${devspace.namespace}
source: none

question

The question option expects a string with a question that will be asked when the variable is not defined. DevSpace tries to resolve the variable according to the source of the variable and if it is not set via any of the accepted sources, DevSpace will prompt the user to define the value by entering a string.

Question
  • Defining the question is optional but often helpful to provide a better usability for other users.
  • If valid options for the variable value are configured, DevSpace will show a picker/selector instead of a regular input field/prompt.
  • If a default value is configured for the variable, DevSpace will use this default value as default answer for the question that can be easily selected by pressing enter.

Default Value For question

question: Please enter a value for [VAR_NAME] # using the variable name

options

The options option expects an array of strings with each string stating a allowed value for the variable.

Example: Define Variable Options

vars:
- name: REGISTRY
question: Which registry do you want to push to?
source: input
options:
- hub.docker.com
- my.private-registry.tld
- gcr.io
default: my.private-registry.tld

Explanation:
If the variable REGISTRY is used for the first time during devspace deploy, DevSpace will ask the user to select which value to use by showing this question:

Which registry do you want to push to? (Default: my.private-registry.tld)
Use the arrows UP/DOWN to select an option and ENTER to choose the selected option.
hub.docker.com
> my.private-registry.tld
gcr.io

noCache

The noCache option expects a boolean that disables the caching behavior for variables. When set to true, this will prompt the user on every run and will not save the value.

Default Value For noCache

noCache: false

password

The password option expects a boolean that defines if DevSpace should hide the user input when the user provides the value for this variable by entering a response to the question asked in the command line.

Default Value For password

password: false

Example: Hide User Response

vars:
- name: REGISTRY_TOKEN
question: "Please enter your registry token:"
source: input
password: true

Explanation:
If the variable REGISTRY_TOKEN is used for the first time during devspace deploy, DevSpace will ask the user to provide a value by showing this question:

? Please enter your registry token: *******

The response the user enters will be hidden as ******* to protect others from seeing the input while the user is typing.

validationPattern

The validationPattern option expects a string stating a regular expression that validates if the value entered by the user is allowed as a value for this variable.

info

If the provided value does not match the regex in validationPattern, DevSpace will either show a generic error message or the message provided in validationMessage.

validationMessage

The validationMessage option expects a string stating an error message that is shown to the user when providing a value for the variable that does not match the regex provided in validationPattern.

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}!