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:
- Custom Functions defined in
devspace.yaml(often added viaimports) - Built-In Functions such as
build_imagesorcreate_deployments
Custom Functions
DevSpace provides support for custom functions. To use them, you need to:
- Declare your custom functions within the
functionssection ofdevspace.yaml - Call custom functions from any scripted field in
devspace.yamlsuch as inpipelinesor 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:
version: v2beta1
functions:
hello_world: |-
echo "Hello World"
get_tag: |-
echo $(git rev-parse --short HEAD)
2. Call Functions
To call a custom function
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:
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 "$@"
build_images [image-1] [image-2] ... pipeline only
Builds all images passed as arguments in parallel
build_images [image-1] [image-2] ... pipeline only--tag / -t []string pipeline only
If enabled will override the default tags
--tag / -t []string pipeline only--skip bool pipeline only
If enabled will skip building
--skip bool pipeline only--skip-push bool pipeline only
Skip pushing
--skip-push bool pipeline only--skip-push-on-local-kubernetes bool pipeline only
Skip pushing
--skip-push-on-local-kubernetes bool pipeline only--force-rebuild bool pipeline only
Skip pushing
--force-rebuild bool pipeline only--sequential bool pipeline only
Skip pushing
--sequential bool pipeline only--max-concurrent int pipeline only
A pointer to an integer
--max-concurrent int pipeline only--all bool pipeline only
Build all images
--all bool pipeline only--except []string pipeline only
If used with --all, will exclude the following images
--except []string pipeline only--set []string pipeline only
Set configuration
--set []string pipeline only--set-string []string pipeline only
Set configuration as string
--set-string []string pipeline only--from []string pipeline only
Reuse an existing configuration
--from []string pipeline only--from-file []string pipeline only
Reuse an existing configuration from a file
--from-file []string pipeline onlyensure_pull_secrets [image-1] [image-2] ... pipeline only
Creates pull secrets for all images passed as arguments
ensure_pull_secrets [image-1] [image-2] ... pipeline only--set []string pipeline only
Set configuration
--set []string pipeline only--set-string []string pipeline only
Set configuration as string
--set-string []string pipeline only--from []string pipeline only
Reuse an existing configuration
--from []string pipeline only--from-file []string pipeline only
Reuse an existing configuration from a file
--from-file []string pipeline only--all bool pipeline only
Ensure all pull secrets
--all bool pipeline only--except []string pipeline only
If used with --all, will exclude the following pull secrets
--except []string pipeline onlycreate_deployments [deployment-1] [deployment-2] ... pipeline only
Creates all deployments passed as arguments in parallel
create_deployments [deployment-1] [deployment-2] ... pipeline only--skip-deploy bool pipeline only
If enabled, will skip deploying
--skip-deploy bool pipeline only--force-redeploy bool pipeline only
Forces redeployment
--force-redeploy bool pipeline only--sequential bool pipeline only
Sequentially deploys the deployments
--sequential bool pipeline only--render bool pipeline only
If true, prints the rendered manifests to the stdout instead of deploying them
--render bool pipeline only--set []string pipeline only
Set configuration
--set []string pipeline only--set-string []string pipeline only
Set configuration as string
--set-string []string pipeline only--from []string pipeline only
Reuse an existing configuration
--from []string pipeline only--from-file []string pipeline only
Reuse an existing configuration from a file
--from-file []string pipeline only--all bool pipeline only
Deploy all deployments
--all bool pipeline only--except []string pipeline only
If used with --all, will exclude the following deployments
--except []string pipeline onlypurge_deployments [deployment-1] [deployment-2] ... pipeline only
Purges all deployments passed as arguments
purge_deployments [deployment-1] [deployment-2] ... pipeline only--force-purge bool pipeline only
Forces purging of deployments even though they might be still in use by other DevSpace projects
--force-purge bool pipeline only--all bool pipeline only
Deploy all deployments
--all bool pipeline only--except []string pipeline only
If used with --all, will exclude the following deployments
--except []string pipeline only--sequential bool pipeline only
Sequentially purges the deployments
--sequential bool pipeline onlystart_dev [dev-1] [dev-2] ... pipeline only
Starts all dev modes passed as arguments
start_dev [dev-1] [dev-2] ... pipeline only--continue-on-terminal-exit bool pipeline only
Continue on terminal exit
--continue-on-terminal-exit bool pipeline only--disable-sync bool pipeline only
If enabled will not start any sync configuration
--disable-sync bool pipeline only--disable-port-forwarding bool pipeline only
If enabled will not start any port forwarding configuration
--disable-port-forwarding bool pipeline only--disable-pod-replace bool pipeline only
If enabled will not replace any pods
--disable-pod-replace bool pipeline only--disable-open bool pipeline only
If enabled will not auto-open the URL
--disable-open bool pipeline only--set []string pipeline only
Set configuration
--set []string pipeline only--set-string []string pipeline only
Set configuration as string
--set-string []string pipeline only--from []string pipeline only
Reuse an existing configuration
--from []string pipeline only--from-file []string pipeline only
Reuse an existing configuration from a file
--from-file []string pipeline only--all bool pipeline only
Start all dev configurations
--all bool pipeline only--except []string pipeline only
If used with --all, will exclude the following dev configs
--except []string pipeline onlystop_dev [dev-1] [dev-2] ... pipeline only
Stops all dev modes passed as arguments
stop_dev [dev-1] [dev-2] ... pipeline onlyrun_pipelines [pipeline-1] [pipeline-2] ... pipeline only
Runs all pipelines passed as arguments
run_pipelines [pipeline-1] [pipeline-2] ... pipeline onlyrun_default_pipeline [pipeline] pipeline only
Runs the default pipeline passed as arguments
run_default_pipeline [pipeline] pipeline onlyrun_dependency_pipelines [dependency-1] [dependency-2] ... pipeline only
Runs a pipeline of each dependency passed as arguments
run_dependency_pipelines [dependency-1] [dependency-2] ... pipeline only--pipeline string pipeline only
The pipeline to deploy from the dependency
--pipeline string pipeline only--exclude []string pipeline only
Dependencies to exclude
--exclude []string pipeline only--only []string pipeline only
Dependencies to include
--only []string pipeline only--sequential bool pipeline only
Run dependencies one after another
--sequential bool pipeline only--set-flag []string pipeline only
Set a pipeline flag
--set-flag []string pipeline only--all bool pipeline only
Deploy all dependencies
--all bool pipeline only--except []string pipeline only
If used with --all, will exclude the following dependencies
--except []string pipeline onlyis_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
is_dependency int pipeline onlyselect_pod string pipeline only
Returns the name of a Kubernetes pod
select_pod string pipeline only--image-selector string pipeline only
The image selector to use to select the container
--image-selector string pipeline only--label-selector string pipeline only
The label selector to use to select the container
--label-selector string pipeline only--container string pipeline only
The container to use
--container string pipeline only--namespace / -n string pipeline only
The namespace to use
--namespace / -n string pipeline only--disable-wait bool pipeline only
If true, will not wait for the container to become ready
--disable-wait bool pipeline only