variables and include feature

Note: This feature is available in version 4.17 and later.

Liquibase Flow files incorporate variables and include other Flow files or YAML files. These can be placed in the Flow file Header above stages:

Read more: flow

globalVariables

globalVariables must be defined at the top of the Flow File with the syntax shown in the example Flow File. Each Action specified in the Flow File can reference a globalVariable as a command argument. This saves you time and keeps your Flow File tidy.

Example globalVariable

offlineRefUrl: "offline:postgres?snapshot=refSnapshot.json"

Example of globalVariable in use

cmdArgs: { url: "${offlineRefUrl}"}

Reference System Environment Variables through globalVariables

globalVariables can reference System Environment Variables to provide values within a Flow file. Within the Flow file example below, notice that the command echos "Running Liquibase from $(LIQUIBASE_HOME)". This allows you to change environment variables as desired without changing the Flow file.

Note:  Place the environment variable you want to reference between the parenthesis: "Running Liquibase from $(INSERT ENVIRONMENT VARIABLE HERE)"

Copy
stages:
    systemEnvironmentVariableSample:
        actions:
        - type: shell
            command: echo "Running Liquibase from ${LIQUIBASE_HOME}"

stageVariables

stageVariables work exactly like globalVariables except they are declared inside of each stage group. If you have the same variable declared as a globalVariable, the stageVariables are applied, not the globalVariable. For example, if you have a changelog globalVariable but need to specify a different changelog, you can apply that via a stageVariable. stageVariables always override globalVariables.

All variables, especially labels and context, must be specified in the Flow File with quotations to operate properly. If you want to run all changesets with or without labels, you must leave the label names quotes empty so you do not have to list all labels individually.

Copy
Label Example 1
Default:
    stageVariables:
      LABELNAMES: ""
Copy
Label Example 2
#
# Run the update
#
- type: liquibase
  command: update
  cmdArgs: {labels: "${LABELNAMES}"}

Include configured YAML files within a Flow File

Flow Files can include references to other YAML files with configuration by using the include section of the file. You need only create a variable name for the referenced YAML file and then reference the file title so that the Flow File can locate it.

The include variable should be in the following format:

username: actual-Username

The key is username and the value is actual-Username. To use the values defined in the included file in the Flow File, you need to reference the namespace and the key. For example:

cmdArgs: {username: "${username}"}

When the flow command executes, it will read the included file, locate the username key and substitute the value for that key into the Liquibase action. In the case of the key:value example here, the substitution results in ${postgresNamespace.user} becoming actual-Username. The Liquibase action executes using actual-Username as the user property.

Example of Flow File include functionality:

include:
- postgresNamespace: postgres-vars.yaml

To enable the functionality, you will then add the created variable name to the cmdArgs section or your changelog.

cmdArgs: { url: "${postgresNamespace.url}", username: "${postgresNamespace.user}", password: "${postgresNamespace.password}", changelog-file: "${postgresNamespace.changelogFile}"}

Related links