set-labels

Note: This is a Liquibase Pro feature, so you need a Liquibase Pro License Key to use it.

The set-labels command sets or replaces labels on your changesets using your command line. This is an alternative to setting labels directly in your changelog.

You can choose which changesets to target by specifying a changeset author, ID, path, or an existing context or label filter.

The command works with any SQL, XML, YAML, or JSON changelog. It also works with multiple changelogs specified with the include or includeAll tags. set-labels is available in Liquibase 4.23.1+.

Uses

If you need to apply labels to many changesets, manually inserting them into your changelog is slow and can lead to errors. Instead, use set-labels to quickly add or replace labels in bulk.

By default, Liquibase appends any labels you specify with set-labels to the list of labels already on your changesets. However, if you set --force-replace to true, Liquibase drops existing labels before adding the new ones.

The command is also useful if you want to standardize multiple similar labels or replace deprecated ones. You can specify command arguments to control the formatting Liquibase uses when it inserts the labels into your changelog.

After setting your labels with set-labels, you can deploy your changes with the update command. While deploying, specify the --labels command argument to control which changesets are run.

Syntax

To run the set-labels command, specify the driver, classpath, and URL in Liquibase properties file. For more information, see Create and Configure a liquibase.properties File. You can also specify these properties in your command line.

Then run the set-labels command:

liquibase set-labels --changelog-file=example-changelog.xml --set-as=dev,test

For example, targeting changesets by author and existing label filter:

liquibase set-labels
    --set-as=rel-02-final
    --changelog-file=release-02.sql
    --changeset-author="bob"
    --label-filter="rel-02"

Replacing existing labels with --force-replace instead of appending them:

liquibase set-labels
    --set-as=rel-02-final
    --changelog-file=release-02.sql
    --changeset-author="bob"
    --context-filter="dev,uat,stage"
    --label-filter="rel-02"
    --force-replace=true

Note: Even though you're setting labels with this command, you can still target changesets using both context-filter and label-filter.

Parameters

Global parameters

Attribute Definition Requirements

--license-key=<string>

Your Liquibase Pro license key

Required

Command parameters

Attribute Definition Requirements

--changelog-file=<string>

The root changelog

Required

--set-as=<string>

Specifies the context(s)/label(s) to apply to the changesets you select. Case-insensitive. Separate multiple values with commas (equivalent to OR) or the AND operator. If you use a space between multiple values, you must surround the entire string with quotes. Otherwise, quotes are optional. For example, --set-as=dev, --set-as="(\!dev and test)" or qa, and --set-as="dev, test" are all valid. User-supplied regular expressions are not supported, but you can use * as a wildcard.

Required

--changeset-author=<string>

The name of the author for the changeset. Supports * as a wildcard.

Optional

--changeset-id=<string>

The changeset ID from the changelog.

Optional

--changeset-path=<string>

The path to the changelog containing the changeset you want to roll back.

Optional

--context-filter=<string>

Specifies the changeset contexts to match. Contexts are tags you can add to changesets to control which changesets are executed in any particular migration run.

Note: If you use Liquibase 4.23.0 or earlier, use the syntax --contexts instead of --context-filter.

Optional

--dbms=<string>

Specifies which database type a changeset is to be used for. See valid database type names on Liquibase Database Tutorials. The keywords all and none are also available.

Optional

--default-catalog-name=<string>

Name of the default catalog to use for the database connection

Optional

--default-schema-name=<string>

Name of the default schema to use for the database connection. If defaultSchemaName is set, then objects do not have to be fully qualified. This means you can refer to just mytable instead of myschema.mytable.

Tip: In Liquibase v4.23.0+, camelCase for defaultSchemaName works successfully. If you are on an earlier version, camelCase may not work as expected.

Note: The syntax liquibase.command.defaultSchemaName is valid for v4.19.0+. For prior versions, use defaultSchemaName.

Optional

--driver=<string>

The JDBC driver class

Optional

--driver-properties-file=<string>

The JDBC driver properties file

Optional

--force-replace=<true|false>

If true, replace any existing contexts/labels with the new ones rather than appending them to the list. If you specify --force-replace without a value, Liquibase sets it to true. Default: false.

Optional

--label-filter=<string>

Specifies the changeset labels to match. Labels are tags you can add to changesets to control which changesets will be executed in any migration run.

Optional

--password=<string>

Password to connect to the target database.

Tip: It is a best practice to store sensitive data in a Secrets Management tool with Liquibase Pro.

Optional

--url=<string>

The JDBC database connection URL. See Using JDBC URL in Liquibase.

Optional

--username=<string>

Username to connect to the target database.

Tip: It is a best practice to store sensitive data in a Secrets Management tool with Liquibase Pro.

Optional

Global parameters

Attribute Definition Requirements

globalArgs: { license-key: "<string>" }

Your Liquibase Pro license key

Required

Command parameters

Attribute Definition Requirements

cmdArgs: { changelog-file: "<string>" }

The root changelog

Required

cmdArgs: { set-as: "<string>" }

Specifies the context(s)/label(s) to apply to the changesets you select. Case-insensitive. Separate multiple values with commas (equivalent to OR) or the AND operator. If you use a space between multiple values, you must surround the entire string with quotes. Otherwise, quotes are optional. For example, --set-as=dev, --set-as="(\!dev and test)" or qa, and --set-as="dev, test" are all valid. User-supplied regular expressions are not supported, but you can use * as a wildcard.

Required

cmdArgs: { changeset-author: "<string>" }

The name of the author for the changeset. Supports * as a wildcard.

Optional

cmdArgs: { changeset-id: "<string>" }

The changeset ID from the changelog.

Optional

cmdArgs: { changeset-path: "<string>" }

The path to the changelog containing the changeset you want to roll back.

Optional

cmdArgs: { context-filter: "<string>" }

Specifies the changeset contexts to match. Contexts are tags you can add to changesets to control which changesets are executed in any particular migration run.

Note: If you use Liquibase 4.23.0 or earlier, use the syntax --contexts instead of --context-filter.

Optional

cmdArgs: { dbms: "<string>" }

Specifies which database type a changeset is to be used for. See valid database type names on Liquibase Database Tutorials. The keywords all and none are also available.

Optional

cmdArgs: { default-catalog-name: "<string>" }

Name of the default catalog to use for the database connection

Optional

cmdArgs: { default-schema-name: "<string>" }

Name of the default schema to use for the database connection. If defaultSchemaName is set, then objects do not have to be fully qualified. This means you can refer to just mytable instead of myschema.mytable.

Tip: In Liquibase v4.23.0+, camelCase for defaultSchemaName works successfully. If you are on an earlier version, camelCase may not work as expected.

Note: The syntax liquibase.command.defaultSchemaName is valid for v4.19.0+. For prior versions, use defaultSchemaName.

Optional

cmdArgs: { driver: "<string>" }

The JDBC driver class

Optional

cmdArgs: { driver-properties-file: "<string>" }

The JDBC driver properties file

Optional

cmdArgs: { force-replace: "<true|false>" }

If true, replace any existing contexts/labels with the new ones rather than appending them to the list. If you specify --force-replace without a value, Liquibase sets it to true. Default: false.

Optional

cmdArgs: { label-filter: "<string>" }

Specifies the changeset labels to match. Labels are tags you can add to changesets to control which changesets will be executed in any migration run.

Optional

cmdArgs: { password: "<string>" }

Password to connect to the target database.

Tip: It is a best practice to store sensitive data in a Secrets Management tool with Liquibase Pro.

Optional

cmdArgs: { url: "<string>" }

The JDBC database connection URL. See Using JDBC URL in Liquibase.

Optional

cmdArgs: { username: "<string>" }

Username to connect to the target database.

Tip: It is a best practice to store sensitive data in a Secrets Management tool with Liquibase Pro.

Optional

Global parameters

Attribute Definition Requirements

liquibase.licenseKey: <string>

Your Liquibase Pro license key

Required

Command parameters

Attribute Definition Requirements

liquibase.command.changelogFile: <string>

liquibase.command.setLabels.changelogFile: <string>

The root changelog

Required

liquibase.command.setAs: <string>

liquibase.command.setLabels.setAs: <string>

Specifies the context(s)/label(s) to apply to the changesets you select. Case-insensitive. Separate multiple values with commas (equivalent to OR) or the AND operator. If you use a space between multiple values, you must surround the entire string with quotes. Otherwise, quotes are optional. For example, --set-as=dev, --set-as="(\!dev and test)" or qa, and --set-as="dev, test" are all valid. User-supplied regular expressions are not supported, but you can use * as a wildcard.

Required

liquibase.command.changesetAuthor: <string>

liquibase.command.setLabels.changesetAuthor: <string>

The name of the author for the changeset. Supports * as a wildcard.

Optional

liquibase.command.changesetId: <string>

liquibase.command.setLabels.changesetId: <string>

The changeset ID from the changelog.

Optional

liquibase.command.changesetPath: <string>

liquibase.command.setLabels.changesetPath: <string>

The path to the changelog containing the changeset you want to roll back.

Optional

liquibase.command.contextFilter: <string>

liquibase.command.setLabels.contextFilter: <string>

Specifies the changeset contexts to match. Contexts are tags you can add to changesets to control which changesets are executed in any particular migration run.

Note: If you use Liquibase 4.23.0 or earlier, use the syntax --contexts instead of --context-filter.

Optional

liquibase.command.dbms: <string>

liquibase.command.setLabels.dbms: <string>

Specifies which database type a changeset is to be used for. See valid database type names on Liquibase Database Tutorials. The keywords all and none are also available.

Optional

liquibase.command.defaultCatalogName: <string>

liquibase.command.setLabels.defaultCatalogName: <string>

Name of the default catalog to use for the database connection

Optional

liquibase.command.defaultSchemaName: <string>

liquibase.command.setLabels.defaultSchemaName: <string>

Name of the default schema to use for the database connection. If defaultSchemaName is set, then objects do not have to be fully qualified. This means you can refer to just mytable instead of myschema.mytable.

Tip: In Liquibase v4.23.0+, camelCase for defaultSchemaName works successfully. If you are on an earlier version, camelCase may not work as expected.

Note: The syntax liquibase.command.defaultSchemaName is valid for v4.19.0+. For prior versions, use defaultSchemaName.

Optional

liquibase.command.driver: <string>

liquibase.command.setLabels.driver: <string>

The JDBC driver class

Optional

liquibase.command.driverPropertiesFile: <string>

liquibase.command.setLabels.driverPropertiesFile: <string>

The JDBC driver properties file

Optional

liquibase.command.forceReplace: <true|false>

liquibase.command.setLabels.forceReplace: <true|false>

If true, replace any existing contexts/labels with the new ones rather than appending them to the list. If you specify --force-replace without a value, Liquibase sets it to true. Default: false.

Optional

liquibase.command.labelFilter: <string>

liquibase.command.setLabels.labelFilter: <string>

Specifies the changeset labels to match. Labels are tags you can add to changesets to control which changesets will be executed in any migration run.

Optional

liquibase.command.password: <string>

liquibase.command.setLabels.password: <string>

Password to connect to the target database.

Tip: It is a best practice to store sensitive data in a Secrets Management tool with Liquibase Pro.

Optional

liquibase.command.url: <string>

liquibase.command.setLabels.url: <string>

The JDBC database connection URL. See Using JDBC URL in Liquibase.

Optional

liquibase.command.username: <string>

liquibase.command.setLabels.username: <string>

Username to connect to the target database.

Tip: It is a best practice to store sensitive data in a Secrets Management tool with Liquibase Pro.

Optional

Global parameters

Attribute Definition Requirements

JAVA_OPTS=-Dliquibase.licenseKey=<string>

Your Liquibase Pro license key

Required

Command parameters

Attribute Definition Requirements

JAVA_OPTS=-Dliquibase.command.changelogFile=<string>

JAVA_OPTS=-Dliquibase.command.setLabels.changelogFile=<string>

The root changelog

Required

JAVA_OPTS=-Dliquibase.command.setAs=<string>

JAVA_OPTS=-Dliquibase.command.setLabels.setAs=<string>

Specifies the context(s)/label(s) to apply to the changesets you select. Case-insensitive. Separate multiple values with commas (equivalent to OR) or the AND operator. If you use a space between multiple values, you must surround the entire string with quotes. Otherwise, quotes are optional. For example, --set-as=dev, --set-as="(\!dev and test)" or qa, and --set-as="dev, test" are all valid. User-supplied regular expressions are not supported, but you can use * as a wildcard.

Required

JAVA_OPTS=-Dliquibase.command.changesetAuthor=<string>

JAVA_OPTS=-Dliquibase.command.setLabels.changesetAuthor=<string>

The name of the author for the changeset. Supports * as a wildcard.

Optional

JAVA_OPTS=-Dliquibase.command.changesetId=<string>

JAVA_OPTS=-Dliquibase.command.setLabels.changesetId=<string>

The changeset ID from the changelog.

Optional

JAVA_OPTS=-Dliquibase.command.changesetPath=<string>

JAVA_OPTS=-Dliquibase.command.setLabels.changesetPath=<string>

The path to the changelog containing the changeset you want to roll back.

Optional

JAVA_OPTS=-Dliquibase.command.contextFilter=<string>

JAVA_OPTS=-Dliquibase.command.setLabels.contextFilter=<string>

Specifies the changeset contexts to match. Contexts are tags you can add to changesets to control which changesets are executed in any particular migration run.

Note: If you use Liquibase 4.23.0 or earlier, use the syntax --contexts instead of --context-filter.

Optional

JAVA_OPTS=-Dliquibase.command.dbms=<string>

JAVA_OPTS=-Dliquibase.command.setLabels.dbms=<string>

Specifies which database type a changeset is to be used for. See valid database type names on Liquibase Database Tutorials. The keywords all and none are also available.

Optional

JAVA_OPTS=-Dliquibase.command.defaultCatalogName=<string>

JAVA_OPTS=-Dliquibase.command.setLabels.defaultCatalogName=<string>

Name of the default catalog to use for the database connection

Optional

JAVA_OPTS=-Dliquibase.command.defaultSchemaName=<string>

JAVA_OPTS=-Dliquibase.command.setLabels.defaultSchemaName=<string>

Name of the default schema to use for the database connection. If defaultSchemaName is set, then objects do not have to be fully qualified. This means you can refer to just mytable instead of myschema.mytable.

Tip: In Liquibase v4.23.0+, camelCase for defaultSchemaName works successfully. If you are on an earlier version, camelCase may not work as expected.

Note: The syntax liquibase.command.defaultSchemaName is valid for v4.19.0+. For prior versions, use defaultSchemaName.

Optional

JAVA_OPTS=-Dliquibase.command.driver=<string>

JAVA_OPTS=-Dliquibase.command.setLabels.driver=<string>

The JDBC driver class

Optional

JAVA_OPTS=-Dliquibase.command.driverPropertiesFile=<string>

JAVA_OPTS=-Dliquibase.command.setLabels.driverPropertiesFile=<string>

The JDBC driver properties file

Optional

JAVA_OPTS=-Dliquibase.command.forceReplace=<true|false>

JAVA_OPTS=-Dliquibase.command.setLabels.forceReplace=<true|false>

If true, replace any existing contexts/labels with the new ones rather than appending them to the list. If you specify --force-replace without a value, Liquibase sets it to true. Default: false.

Optional

JAVA_OPTS=-Dliquibase.command.labelFilter=<string>

JAVA_OPTS=-Dliquibase.command.setLabels.labelFilter=<string>

Specifies the changeset labels to match. Labels are tags you can add to changesets to control which changesets will be executed in any migration run.

Optional

JAVA_OPTS=-Dliquibase.command.password=<string>

JAVA_OPTS=-Dliquibase.command.setLabels.password=<string>

Password to connect to the target database.

Tip: It is a best practice to store sensitive data in a Secrets Management tool with Liquibase Pro.

Optional

JAVA_OPTS=-Dliquibase.command.url=<string>

JAVA_OPTS=-Dliquibase.command.setLabels.url=<string>

The JDBC database connection URL. See Using JDBC URL in Liquibase.

Optional

JAVA_OPTS=-Dliquibase.command.username=<string>

JAVA_OPTS=-Dliquibase.command.setLabels.username=<string>

Username to connect to the target database.

Tip: It is a best practice to store sensitive data in a Secrets Management tool with Liquibase Pro.

Optional

Global parameters

Attribute Definition Requirements

LIQUIBASE_LICENSE_KEY=<string>

Your Liquibase Pro license key

Required

Command parameters

Attribute Definition Requirements

LIQUIBASE_COMMAND_CHANGELOG_FILE=<string>

LIQUIBASE_COMMAND_SET_LABELS_CHANGELOG_FILE=<string>

The root changelog

Required

LIQUIBASE_COMMAND_SET_AS=<string>

LIQUIBASE_COMMAND_SET_LABELS_SET_AS=<string>

Specifies the context(s)/label(s) to apply to the changesets you select. Case-insensitive. Separate multiple values with commas (equivalent to OR) or the AND operator. If you use a space between multiple values, you must surround the entire string with quotes. Otherwise, quotes are optional. For example, --set-as=dev, --set-as="(\!dev and test)" or qa, and --set-as="dev, test" are all valid. User-supplied regular expressions are not supported, but you can use * as a wildcard.

Required

LIQUIBASE_COMMAND_CHANGESET_AUTHOR=<string>

LIQUIBASE_COMMAND_SET_LABELS_CHANGESET_AUTHOR=<string>

The name of the author for the changeset. Supports * as a wildcard.

Optional

LIQUIBASE_COMMAND_CHANGESET_ID=<string>

LIQUIBASE_COMMAND_SET_LABELS_CHANGESET_ID=<string>

The changeset ID from the changelog.

Optional

LIQUIBASE_COMMAND_CHANGESET_PATH=<string>

LIQUIBASE_COMMAND_SET_LABELS_CHANGESET_PATH=<string>

The path to the changelog containing the changeset you want to roll back.

Optional

LIQUIBASE_COMMAND_CONTEXT_FILTER=<string>

LIQUIBASE_COMMAND_SET_LABELS_CONTEXT_FILTER=<string>

Specifies the changeset contexts to match. Contexts are tags you can add to changesets to control which changesets are executed in any particular migration run.

Note: If you use Liquibase 4.23.0 or earlier, use the syntax --contexts instead of --context-filter.

Optional

LIQUIBASE_COMMAND_DBMS=<string>

LIQUIBASE_COMMAND_SET_LABELS_DBMS=<string>

Specifies which database type a changeset is to be used for. See valid database type names on Liquibase Database Tutorials. The keywords all and none are also available.

Optional

LIQUIBASE_COMMAND_DEFAULT_CATALOG_NAME=<string>

LIQUIBASE_COMMAND_SET_LABELS_DEFAULT_CATALOG_NAME=<string>

Name of the default catalog to use for the database connection

Optional

LIQUIBASE_COMMAND_DEFAULT_SCHEMA_NAME=<string>

LIQUIBASE_COMMAND_SET_LABELS_DEFAULT_SCHEMA_NAME=<string>

Name of the default schema to use for the database connection. If defaultSchemaName is set, then objects do not have to be fully qualified. This means you can refer to just mytable instead of myschema.mytable.

Tip: In Liquibase v4.23.0+, camelCase for defaultSchemaName works successfully. If you are on an earlier version, camelCase may not work as expected.

Note: The syntax liquibase.command.defaultSchemaName is valid for v4.19.0+. For prior versions, use defaultSchemaName.

Optional

LIQUIBASE_COMMAND_DRIVER=<string>

LIQUIBASE_COMMAND_SET_LABELS_DRIVER=<string>

The JDBC driver class

Optional

LIQUIBASE_COMMAND_DRIVER_PROPERTIES_FILE=<string>

LIQUIBASE_COMMAND_SET_LABELS_DRIVER_PROPERTIES_FILE=<string>

The JDBC driver properties file

Optional

LIQUIBASE_COMMAND_FORCE_REPLACE=<true|false>

LIQUIBASE_COMMAND_SET_LABELS_FORCE_REPLACE=<true|false>

If true, replace any existing contexts/labels with the new ones rather than appending them to the list. If you specify --force-replace without a value, Liquibase sets it to true. Default: false.

Optional

LIQUIBASE_COMMAND_LABEL_FILTER=<string>

LIQUIBASE_COMMAND_SET_LABELS_LABEL_FILTER=<string>

Specifies the changeset labels to match. Labels are tags you can add to changesets to control which changesets will be executed in any migration run.

Optional

LIQUIBASE_COMMAND_PASSWORD=<string>

LIQUIBASE_COMMAND_SET_LABELS_PASSWORD=<string>

Password to connect to the target database.

Tip: It is a best practice to store sensitive data in a Secrets Management tool with Liquibase Pro.

Optional

LIQUIBASE_COMMAND_URL=<string>

LIQUIBASE_COMMAND_SET_LABELS_URL=<string>

The JDBC database connection URL. See Using JDBC URL in Liquibase.

Optional

LIQUIBASE_COMMAND_USERNAME=<string>

LIQUIBASE_COMMAND_SET_LABELS_USERNAME=<string>

Username to connect to the target database.

Tip: It is a best practice to store sensitive data in a Secrets Management tool with Liquibase Pro.

Optional

Note: The username and password attributes are not required for connections and systems which use alternate means of authentication. Also, you can specify database credentials as part of the url attribute.

Output

When successful, the set-labels command produces the following output:

* Changelog file 'changelog.xml' modified successfully.
Liquibase command 'set-labels' was executed successfully.

If you specify an invalid value for the dbms argument:

Mismatched dbms for changeset 'createPrimaryTable::Liquibase Pro User::changelog.xml'

When there is an ignored changeset:

Ignoring changeset 'createSecondaryTable::Liquibase Pro User::changelog.xml'

When there is nothing to modify:

* Changelog file 'changelog.xml' was not modified.

Related links