Custom Policy Check property substitution

In Liquibase Pro 4.31+, you can utilize Custom Policy Checks alongside property substitution when setting the SCRIPT_ARGS during check creation. You can reference properties such as environment variables, CLI arguments, or values from the liquibase.properties file using standard property substitution syntax. This enables dynamic and context-aware scripting, such as configuring behavior based on runtime attributes like the current Git branch or target environment. It makes your Custom Policy Checks more flexible, reusable, and maintainable. The values to replace in your Custom Policy Check are described using the ${property.name} syntax.

Uses

By substituting values for replacement values in the format of ${property.name}, you can use the same SCRIPT_ARGS to reflect small environmental changes.

For example, your tablespace name in Oracle may differ from environment to environment, but you want to only write one create table changeset that can be used in all of your environments.

Example scenario 1:

In this example, a Python script needs to run against a target URL, but you don’t know the URL ahead of time. Instead of hard coding it, you can use the value that Liquibase sets for liquibase.command.url, since that’s always the correct target for each operation.

By adding the below script to the Custom Policy Check script, Liquibase can then use that value automatically.

targeturl= "${liquibase.command.url}"

Example scenario 2: 

In this example, the script needs to behave differently depending on who owns the pipeline. If the pipeline name starts with UK_DEV_APPS_, you want to run a conditional action. I can do this by passing a variable like ${PIPELINE_NAME} into my script, and using Python to check if the name starts with UK_DEV_APPS_.

By adding the below script to the Custom Policy Check script, Liquibase can decide whether to run certain actions or skip them.

pipelinename="${PIPELINE.TEAM}"

Next steps

Apply Property substitution in Custom policy checks