Skip to main content
Version: 6.x (Latest)

Functions

Functions are bash functions that can be called inside the remainder of devspace.yaml. A common use case is to define reusable functionality that is called from within the scripts you specify within the pipelines section.

There are two types of functions:

  1. Custom Functions defined in devspace.yaml (often added via imports)
  2. Built-In Functions such as build_images or create_deployments

Custom Functions

DevSpace provides support for custom functions. To use them, you need to:

  1. Declare your custom functions within the functions section of devspace.yaml
  2. Call custom functions from any scripted field in devspace.yaml such as in pipelines or in any value defined using an inline script such as $(command)

1. Declare Functions

Declaring a function means adding a key with the function name to the functions section in devspace.yaml as shown in the example below:

devspace.yaml
version: v2beta1
functions:
hello_world: |-
echo "Hello World"
get_tag: |-
echo $(git rev-parse --short HEAD)

2. Call Functions

To call a custom function

devspace.yaml
version: v2beta1
pipelines:
deploy: |-
build_images --tag $(get_git_commit)
create_deployments --all
dev: |-
hello_world
run_default_pipeline dev

Please note that custom functions can only be called from pipelines and other functions as these run in a pipeline context.

Built-In Functions

DevSpace provides a set of built-in functions. There are two types of functions:

  1. Pipeline-Only Functions
  2. Global Functions

Pipeline-Only Functions

Pipeline-only functions can only be used inside the scripts within the pipelines section of devspace.yaml. They can be overridden through the functions section to avoid changing a default pipeline.

Example:

functions:
create_deployments: |-
echo "create_deployments was called with $@"
__create_deployments "$@"
Images

build_images [image-1][image-2] ... pipeline only

Builds all images passed as arguments in parallel

--tag / -t []string pipeline only

If enabled will override the default tags

--skip bool pipeline only

If enabled will skip building

--skip-push bool pipeline only

Skip pushing

--skip-push-on-local-kubernetes bool pipeline only

Skip pushing

--force-rebuild bool pipeline only

Skip pushing

--sequential bool pipeline only

Skip pushing

--max-concurrent int pipeline only

A pointer to an integer

--all bool pipeline only

Build all images

--except []string pipeline only

If used with --all, will exclude the following images

--set []string pipeline only

Set configuration

--set-string []string pipeline only

Set configuration as string

--from []string pipeline only

Reuse an existing configuration

--from-file []string pipeline only

Reuse an existing configuration from a file

ensure_pull_secrets [image-1][image-2] ... pipeline only

Creates pull secrets for all images passed as arguments

--set []string pipeline only

Set configuration

--set-string []string pipeline only

Set configuration as string

--from []string pipeline only

Reuse an existing configuration

--from-file []string pipeline only

Reuse an existing configuration from a file

--all bool pipeline only

Ensure all pull secrets

--except []string pipeline only

If used with --all, will exclude the following pull secrets

get_image [image] string pipeline only

Returns the most recently built image and/or tag for a given image name

--dependency string pipeline only

Retrieves the image from the named dependency

--only string pipeline only

Displays either only the tag or only the image

Deployments

create_deployments [deployment-1][deployment-2] ... pipeline only

Creates all deployments passed as arguments in parallel

--skip-deploy bool pipeline only

If enabled, will skip deploying

--force-redeploy bool pipeline only

Forces redeployment

--sequential bool pipeline only

Sequentially deploys the deployments

--render bool pipeline only

If true, prints the rendered manifests to the stdout instead of deploying them

--set []string pipeline only

Set configuration

--set-string []string pipeline only

Set configuration as string

--from []string pipeline only

Reuse an existing configuration

--from-file []string pipeline only

Reuse an existing configuration from a file

--all bool pipeline only

Deploy all deployments

--except []string pipeline only

If used with --all, will exclude the following deployments

purge_deployments [deployment-1][deployment-2] ... pipeline only

Purges all deployments passed as arguments

--force-purge bool pipeline only

Forces purging of deployments even though they might be still in use by other DevSpace projects

--all bool pipeline only

Deploy all deployments

--except []string pipeline only

If used with --all, will exclude the following deployments

--sequential bool pipeline only

Sequentially purges the deployments

Dev

start_dev [dev-1][dev-2] ... pipeline only

Starts all dev modes passed as arguments

--continue-on-terminal-exit bool pipeline only

Continue on terminal exit

--disable-sync bool pipeline only

If enabled will not start any sync configuration

--disable-port-forwarding bool pipeline only

If enabled will not start any port forwarding configuration

--disable-pod-replace bool pipeline only

If enabled will not replace any pods

--disable-open bool pipeline only

If enabled will not replace any pods

--set []string pipeline only

Set configuration

--set-string []string pipeline only

Set configuration as string

--from []string pipeline only

Reuse an existing configuration

--from-file []string pipeline only

Reuse an existing configuration from a file

--all bool pipeline only

Start all dev configurations

--except []string pipeline only

If used with --all, will exclude the following dev configs

stop_dev [dev-1][dev-2] ... pipeline only

Stops all dev modes passed as arguments

--force-purge bool pipeline only

Forces purging of deployments even though they might be still in use by other DevSpace projects

--all bool pipeline only

Stop all dev configurations

--except []string pipeline only

If used with --all, will exclude the following dev configs

Pipelines

run_pipelines [pipeline-1][pipeline-2] ... pipeline only

Runs all pipelines passed as arguments

--background bool pipeline only

Run the pipeline in the background

--sequential bool pipeline only

Run pipelines one after another

--set-flag []string pipeline only

Set a pipeline flag

--set []string pipeline only

Set configuration

--set-string []string pipeline only

Set configuration as string

run_default_pipeline [pipeline] pipeline only

Runs the default pipeline passed as arguments

run_dependency_pipelines [dependency-1][dependency-2] ... pipeline only

Runs a pipeline of each dependency passed as arguments

--pipeline string pipeline only

The pipeline to deploy from the dependency

--exclude []string pipeline only

Dependencies to exclude

--only []string pipeline only

Dependencies to include

--sequential bool pipeline only

Run dependencies one after another

--set-flag []string pipeline only

Set a pipeline flag

--all bool pipeline only

Deploy all dependencies

--except []string pipeline only

If used with --all, will exclude the following dependencies

Checks

is_dependency int pipeline only

Returns exit code 0 if the pipeline currently being executed is run because the project is a dependency of another project

Other

select_pod string pipeline only

Returns the name of a Kubernetes pod

--image-selector string pipeline only

The image selector to use to select the container

--label-selector string pipeline only

The label selector to use to select the container

--container string pipeline only

The container to use

--namespace / -n string pipeline only

The namespace to use

--disable-wait bool pipeline only

If true, will not wait for the container to become ready

--timeout int64 pipeline only

The timeout to wait. Defaults to 5 minutes

wait_pod [command] pipeline only

Waits for a pod to become running

--image-selector string pipeline only

The image selector to use to select the container

--label-selector string pipeline only

The label selector to use to select the container

--container string pipeline only

The container to use

--namespace / -n string pipeline only

The namespace to use

--disable-wait bool pipeline only

If true, will not wait for the container to become ready

--timeout int64 pipeline only

The timeout to wait. Defaults to 5 minutes

exec_container [command] pipeline only

Executes the command provided as argument inside a container

--image-selector string pipeline only

The image selector to use to select the container

--label-selector string pipeline only

The label selector to use to select the container

--container string pipeline only

The container to use

--namespace / -n string pipeline only

The namespace to use

--disable-wait bool pipeline only

If true, will not wait for the container to become ready

--timeout int64 pipeline only

The timeout to wait. Defaults to 5 minutes

get_config_value [json.path] string pipeline only

Returns the value of the config loaded from devspace.yaml

Global Functions

Global functions can be used anywhere in devspace.yaml, either in config fields that expect a bash script such as within functions or using $(command) vars in any other config field.

Checks

is_empty [value] int pipeline only

Returns exit code 0 if the value of the argument is empty string

is_equal [value-1][value-2] int pipeline only

Returns exit code 0 if the values of both arguments provided are equal

is_in [value-1][value-2] int pipeline only

Returns exit code 0 if the value of the first argument can be found in the second argument (second argument being a blank-separated list of strings e.g "bananas apples peaches")

is_os [os] darwin linux windows aix android dragonfly freebsd hurd illumos ios js nacl netbsd openbsd plan9 solaris zos int pipeline only

Returns exit code 0 if the current operating system equals the value provided as argument

is_true [value] int pipeline only

Returns exit code 0 if the value of the argument is "true"

Other

cat [file-path] string pipeline only

Returns the content of a file

get_flag [flag-name] string pipeline only

Returns the value of the flag that is provided as argument

run_watch [command] pipeline only

Executes the command provided as argument and watches for conditions to restart the command

--fail-on-error bool pipeline only

If true the command will fail on an error while running the sub command

--skip-initial bool pipeline only

If true will not execute the command immediately.

--silent bool pipeline only

If true will not print any warning about restarting the command.

--skip-and-silent / -s bool pipeline only

If enabled will not print when the command is restarted and not execute the command initially.

--exclude / -e []string pipeline only

The paths to ignore. Can be patterns in the form of ./**/my-file.txt

--path / -p []string pipeline only

The paths to watch. Can be patterns in the form of ./**/my-file.txt

sleep [seconds] pipeline only

Pauses the script execution for the number of seconds provided as argument

xargs [command] pipeline only

Reads from stdin, splits input by blanks and executes the command provided as argument for each blank-separated input value (often used in pipes, e.g. echo 'image-1 image-2' | xargs build_images)

Config Reference

functions required <function_name>:string

Functions are POSIX functions that can be used within pipelines. Those functions can also be imported by imports.