description: Component actions examples
# See the example README.md in this folder or /adrs/0010-scripts-actions.md for more info.
# runs during "zarf package create"
# defaults are applied to all actions in this action set - below are the default defaults
# runs before the component is created
# on Windows with `pwsh` or `powershell`, `touch` is replaced with New-Item
- cmd: touch test-create-before.txt
# description shows a more user friendly message when waiting for the command
description: Create a test file
# dir is the directory to run the command in
# env sets environment variables for this action only
# maxRetries is the number of times to retry the action if it fails
# maxTotalSeconds is the maximum amount of times the action can run before it is killed, over all retries
# mute determine if actions output should be printed to the console
# shell sets the preferred shell across operating systems, in this case "pwsh" instead of "powershell" on Windows
# runs after the component is created
# actions in a list run in order
- cmd: touch test-create-after.txt
- cmd: echo "I can print!"
# cmd actions can also specify a multiline string to run like a script
- name: on-deploy-and-remove
# runs during "zarf package deploy"
# runs before the component is deployed
- cmd: touch test-deploy-before.txt
# runs after the component is deployed
- cmd: touch test-deploy-after.txt
# runs during "zarf package remove"
# runs before anything else from the component is removed
- cmd: rm test-deploy-before.txt
# runs after everything else from the component is removed
- cmd: rm test-deploy-after.txt
- name: on-deploy-with-variable
# runs during "zarf package deploy"
# runs before the component is deployed
- cmd: echo "the dog says ${ZARF_VAR_DOG_SOUND}"
- name: on-deploy-with-dynamic-variable
# runs during "zarf package deploy"
# runs before the component is deployed
# setVariables can be used to set a variable for use in other actions or components
# the name of the variable to set with the output of the action (only useable onDeploy)
# this action will have access to the variable set in the previous action
- cmd: echo "the cat says ${ZARF_VAR_CAT_SOUND}"
- name: on-deploy-with-multiple-variables
# runs during "zarf package deploy"
# runs before the component is deployed
# setting this variable will allow it to be used in other actions with additional variables
# set in other actions or components
# setVariables defines a list of variables to set from the `cmd` standard out.
# marks this variable as sensitive to prevent it from being output in the Zarf log
# autoIndent tells Zarf to maintain spacing for any newlines when templating into a yaml file
# onSuccess will only run if steps in this component are successful
# this action will print the CAT_SOUND variable that was set in a previous component
- cmd: echo "the cat says ${ZARF_VAR_CAT_SOUND}"
# this action will print the DOG_SOUND variable set at the top of the zarf.yaml file
- cmd: echo "the dog says ${ZARF_VAR_DOG_SOUND}"
# this action will print the SNAKE_SOUND variable set within this component
# > NOTE: when including a variable in a command output this will be written to the log regardless of the sensitive setting
# - use `mute` if you want to silence the command output for sensitive variables
- cmd: echo "the snake says ${ZARF_VAR_SNAKE_SOUND}"
# variables are also exposed as TF_VAR_name for terraform, note the lowercase variable name
- cmd: echo "with a TF_VAR, the snake also says ${TF_VAR_snake_sound}"
- name: on-deploy-with-template-use-of-variable
# this file will be copied to the target location and the cat, dog, and snake sounds will be replaced with their values
# requires the on-deploy-with-dynamic-variable and on-deploy-with-multiple-variables components
target: test-templated.txt
shasum: 3c0404e0c767ace905c361fadded6c4b91fdb88aa07d5c42d2a220a87564836d
- name: on-deploy-with-timeout
description: This component will fail after 1 second
# runs during "zarf package deploy"
# defaults allow you to specify default values for the actions in that actionSet
# maxTotalSeconds is the maximum amount of time the action can run before it is killed, over all retries
# this action will fail after 1 second
- cmd: echo "ðŸ˜ðŸ˜ðŸ˜ this action failed because it took too long to run ðŸ˜ðŸ˜ðŸ˜"
# A manifest that we expect to be removed by Zarf
# runs during "zarf package remove"
# because this runs before the manifest is removed this should return our manifest
- cmd: ./zarf tools kubectl get configmap -n zarf remove-test-configmap || echo
# because this runs after the manifest is removed this should no longer be found
- cmd: ./zarf tools kubectl get configmap -n zarf remove-test-configmap || echo
- name: on-deploy-with-env-var
- cmd: touch $ZARF_VAR_TEST_FILENAME
# this will set the env var ZARF_VAR_TEST_FILENAME - useful for passing information into scripts
- ZARF_VAR_TEST_FILENAME=test-filename-from-env.txt
- name: on-create-with-network-wait-action
description: This component will wait for 15 seconds for a network resource to
- description: Github.com to be available
# wait for a network address to return a 200 OK response
- name: on-deploy-with-wait-action
description: This component will wait for 5 seconds for the test-configmap to be exist
- description: The simple-configmap to exist
# wait for the configmap to be available in the cluster
- name: on-deploy-immediate-failure
description: This component will fail on the first error instead of continuing execution
# the default for multi-line commands is set -e
echo "this text shouldn't be printed"