Exit a Flow file

Using the Control command, exit, in a flow file allows you to exit running the flow if there are not any pending changesets present. This enhances your efficiency when using a flow file by eliminating the need to run checks on unchanged changesets or generate drift reports when no changes are being applied.

Note: Available with a Liquibase Pro license key in +4.30.0

Procedure

  1. To use the exit Control command in a Control step of a Flow file, you must run the status command within the Flow file and set the next -type argument to -type: control along with the necessary arguments.

    Copy
    Include the status command and type: control in the flow file
    - type: liquibase
          command: status
        
    - type: control
  2. Note: If you want to use Labels, add them here. You must add them under the status command, not the exit command.

    The exit command has two command arguments:

    • exitCode: 0 This is an integer and does not require quotes in its syntax.
    • exitMessage: "a string" This is a string and requires quotes in its syntax.
  3. Set the exitCode to 0-4 depending on the severity you want to trigger.
  4. Set the exitMessage.
    Example: Exiting with an error status of 0 because the database is up-to-date.
  5. Set the if: "status.changeset.Count == 0". This will trigger the command to exit if Liquibase detects there are no pending deployed changesets.

    This completes all of the Flow file changes to enable the exit control command. Next, you will move back to the CLI to run the Flow.
    Copy
    Complete Flow file example
    stages:
      stage-status-check:

        #
        # Exit if no pending changes to deploy
        #
        - type: liquibase
          command: status
        
        - type: control
          if: "status.changesetCount == 0"
          command: exit
          cmdArgs: {exitCode: 0, exitMessage: "Exiting with an error status of 0 because the database is up-to-date"}
  6. Note: A child Flow cannot cause a parent flow to exit. status commands must be run in the same Flow file that contains the control being checked.

  7. After you set up your Flow file, run the flow command in the CLI:
  8. liquibase flow --flow-file=flows/<path/to/your/flowfile>.yaml

    The type:control action runs, and if no new changesets are detected, Liquibase exits the Flow.