Shell Commands

Using Shell Commands in a flow file allows you to access your shell from a Liquibase operation. You can join multiple commands in sequence, or redirect output to files for later processing which can be done via cat, grep, or other methods.
Note: The flow
feature requires Liquibase 4.17+.
Syntax
To use shell commands in your Flow file, you must set the type
argument to shell
rather than liquibase
:
- type: shell
command: foobar
You can use a single command here or chain multiple commands together with &&
. For example, to print the environment variables that begin with 'LIQUIBASE_'
:
echo 'Printing LIQUIBASE_* env vars' && env | grep 'LIQUIBASE_'
Alternatively, you can put bash -c
in front of a double-quoted command, which runs a completely new shell. (You can use a similar method to invoke cmd, gitbash, or similar.) If you need to quote something inside of the command, use single quotes to distinguish the inside from the outside of the shell command in double quotes:
bash -c "echo 'Printing LIQUIBASE_* env vars' && env | grep 'LIQUIBASE_'"
stages:
chainedCommandExample:
actions:
- type: shell
#command: bash -c "echo 'Printing Liquibase_* env vars' && env | grep 'LIQUIBASE_'"
command: echo 'Printing LIQUIBASE_* env vars' && env | grep 'LIQUIBASE_'
After you set up your Flow file, run liquibase flow
:
liquibase flow --flow-file=flows/<path/to/your/flowfile>.yaml
The shell bash commits successfully and all environment variables display as intended.
Shell command options
- Shell commands that utilize an equals sign (
=
) can be applied in flow files. - You can specify the shell interpreter to execute the shell command.
Example: This can include but is not limited to bash, cmd, powershell, etc.
- type: shell
command: bash -c "UNDEPLOYED=$(grep -c 'have not been applied' './${PROJNAME}/${STATUSFILE}') && echo $UNDEPLOYED" - Multi-line shell commands can be applied in flow files. This can be applied by using the vertical line character (
|
) to begin the command.Example:
- type: shell
command: |
UNDEPLOYED=$(grep -c 'have been applied' '/tmp/status.txt')
echo $UNDEPLOYED
Example: One of the many ways to use this feature is by exporting ENV vars from within a flow command to use later.- type: shell
command: bash -c "UNDEPLOYED=$(grep -c 'have not been applied' './${PROJNAME}/${STATUSFILE}') && echo $UNDEPLOYED"