Manage values in YAML
You can manage values separately from your DevOps as Code YAML files so that they can be pulled in when applying XL YAML files. DevOps as Code supports multiple methods to configure and manage values including a dedicated file format using the
.xlvals extension, environment variables or by explicitly specifying a value in XL CLI command syntax.
Methods to manage values
Each of the following methods are parsed in the order presented below.
- Method 1: One or more
.xlvalsfiles in the
/.xebialabsfolder in your home directory. Multiple files in this folder are parsed in alphabetical order.
Method 2: One or more
.xlvalsfiles in your project directory alongside your YAML files.
- A YAML file can only parse
.xlvalsfiles stored in the same directory.
- You can have a YAML file stored at a higher level in the directory structure that imports one or more YAML files that reside in a subdirectory. However, any
.xlvalsfiles related to a YAML file in a subdirectory must be in the same directory.
.xlvalsfiles in this directory are parsed in alphabetical order.
- A YAML file can only parse
- Method 3: Environment variables that are prefixed with
XL_VALUE_; for example,
- Method 4: Invoked explicitly as a parameter when using the XL CLI; for example, by adding the global flag
How value methods are parsed
The XL CLI will parse the methods for managing values in the order implied in the method order described above.
- If there are multiple
.xlvalsfiles in a directory, each file will be parsed in alphabetical order.
- If you have multiple environment variables defined that are prefixed with
XL_VALUE_, each variable will be parsed in alphabetical order.
- If a duplicate key is encountered as parsing continues through the method order, the last encountered key is used. For example, if you have a value defined for
.xlvalsfile in your
.xebialabsdirectory (method 1), and you have the different value for
USERdefined in an
.xlvalsfile in your project directory (method 2), then the value in the project directory is used and the value in the
.xebialabsdirectory is ignored.
.xlvals file format
.xlvals file is simply a list of keys and values, and follows the standard implementation of the Java
.properties file format.
Here is an example of key/value definitions using the
# my keys and values appversion=1.0.2 environmentName=myenv hostname=myhostname port=443
You can configure and use environment variables on your system by using the
XL_VALUE_ prefix. For example:
Command line syntax for values
You can specify a key “on the fly” during execution of an XL CLI command using the
--values global flag. This example shows how to pass multiple keys:
xl apply -f xldeploy/application.yaml --values myvar1=val1,myvar2=val2
Using values in your YAML files
Once you have defined your values using one of the methods described above, you can use
!format tags in your YAML files to specify a key for which the corresponding value will be pulled in when the YAML file is applied.
!value tag simply takes the name as a parameter. For example:
environment: !value environmentName
You can use the
!format tag for more complex values such as URLs or path names. You can use a string and encapsulate using the
% symbol to mark the value name. For example:
apiServerURL: !format https://%hostname%:%port%
You can escape
% characters by doubling them. For example, if
15, the following line:
percentage: !format %value%%%
Manage secret values
Any sensitive fields can be added to the template as
!value keys, and passed in
xl apply either in
.xlvals files or directly in the CLI. This method has the advantage of not storing secrets in templates, and instead being able to put the secrets values file into a secure location such as a
xl generate, secret values will automatically be set as
!value keys. Admins can use the
--secrets flag to generate a
secrets.xlvals file with the values supplied.