How to use variables in WildFly CLI

In this short tutorial we will learn how to use variables in WildFly / JBoss Command Line Interface (CLI) showing some examples and hacks to get the most of it.

Declaring Variables in the CLI

First things first: WildFly CLI has a set function that you can use to assign a certain path of the server model to a variable. Example:

[standalone@localhost:9990 /] set s1=/host=master/server=server-one

This is quite useful in domain mode as you can include references to host and profiles in variables so that you can easily replicate scripts on different servers. Example:

[standalone@localhost:9990 /] $s1/subsystem=datasources/data-source=ExampleDS:test-connection-in-pool

You can also set multiple variables at once by using a space as separator. Example:

[standalone@localhost:9990 /] set var1=value1 var2=value2

To get the list of variables available in the current CLI Session, just use the set command:

[standalone@localhost:9990 /] set

Here is a nice hack. If you are running the CLI from within a bash script:, you can bundle the variables within the Bash script as in this example:



$JBOSS_HOME/bin/ --connect <<EOF







How to make CLI variables persistent

By default, all variables set within the CLI session will be lost at the end of the session. Luckily the .jbossclirc file comes to rescue us. Firstly, include the variables in this file (available in the “bin” folder of your server installation):

# .jbossclirc
set s1=/host=master/server=server-one
set s2=/host=master/server=server-two

Next restart the CLI and issue a set command to check the available variables:

[domain@localhost:9990 /] set

Using variables to set attributes

You can also use variables to set values of your configuration. Let’s see an example:

[standalone@localhost:9990 /] set MYVAR=foo
[standalone@localhost:9990 /] /system-property=test:add(value="${MYVAR}")

However, the above command fails with:

    "outcome" => "failed",
    "failure-description" => "WFLYCTL0211: Cannot resolve expression '${MYVAR}'",
    "rolled-back" => true

That’s because you need to use a different format in your CLI to set values with variables. You need to include a colon (“:”) when setting attributes. That also allows setting a default value. The following will work:


Finally, here is how to allow a default value for your variable:


Using environment variables in the CLI

Within the application server configuration, it is common to use this Beanshell expression to refer to environment variables:


However, if you try to use the above expression with the CLI, you won’t get the actual value of the environment variable:

[standalone@localhost:9990 /] echo ${env.MODULEPATH}

To allow it, edit the jboss-cli.,xml and set the attribute resolve-parameter-values to true:

<!-- whether to resolve system properties specified as command argument or operation parameter values
                 in the CLI VM before sending the operation requests to the controller -->

With that in place, restart the CLI and you will be able to reference the environment variable:

[standalone@localhost:9990 /] echo ${env.MODULEPATH}

How to create aliases for commands

Finally, we will discuss about using aliases in the CLI. WildFly CLI can use aliases pretty much the same you would do it in a Linux Box:

[domain@localhost:9990 /] alias ll='ls'
[domain@localhost:9990 /] ll
core-service                    management-client-content       domain-organization=undefined   name=Unnamed Domain             release-version=2.0.10.Final    
deployment                      path                            launch-type=DOMAIN              namespaces=[]                   schema-locations=[]             
deployment-overlay              profile                         local-host-name=master          process-type=Domain Controller  
extension                       server-group                    management-major-version=4      product-name=WildFly Full       
host                            socket-binding-group            management-micro-version=0      product-version=10.0.0.Final    
interface                       system-property                 management-minor-version=0      release-codename=Kenny

As for variables, the alias created in a CLI session are not persistent. Since the CLI is derived from the Aesh project ( , aliases can be defined in the .aesh_aliases within the user’s home folder (Not WildFly home!).

Let’s test it. We will add the following alias in $HOME/.aesh_aliases

alias create='/subsystem=ejb3/strict-max-bean-instance-pool=demo:add(max-pool-size=10)'

Now start the CLI and test it:

[francesco@localhost bin]$ ./ -c
[standalone@localhost:9990 /] alias
alias create='/subsystem=ejb3/strict-max-bean-instance-pool=demo:add(max-pool-size=10)'
[standalone@localhost:9990 /] create
{"outcome" => "success"}

You could be also interested in the following tutorial:  Using properties in CLI scripts