Search code examples
dockerjboss

How to pass a docker variable to jboss-cli.sh?


I have a variable in my jboss cli file, let's call it ${FOO}.

I can see that the variable is set in my Dockerfile, if I:

RUN echo ${FOO}

I see the value printed.

I have a foo.cli file which contains a line similar to:

/system-property=foo:add(value="${FOO}")

and when I run jboss-cli.sh foo.cli

I get:

Cannot resolve expression ${FOO}.

Is there a way to pass a variable from Docker to the file argument to jboss-cli.sh ?

I've tried removing the quotes around ${FOO} also in the system-property line but no luck.


Solution

  • This is due to the fact that the CLI does not treat values the same as names. In short, operation names, parameter names, header names and values, command names as well as command argument names are resolved automatically. Parameter and argument values aren’t. To fix this, we need to set resolve-parameter-values to true in jboss-cli.xml.

    For e.g.:-

    sed -i "s/<resolve-parameter-values>false<\/resolve-parameter-values>/\
    <resolve-parameter-values>true<\/resolve-parameter-values>/" \
    $JBOSS_HOME/bin/jboss-cli.xml
    

    Note that the command above is meant to be a one-off solution. From the maintenance perspective, using sed for XML is not a good idea in general. If you’re automating this, consider using XPath instead.

    Note:- This functionality requires WildFly 8.0.0.CR1 or newer.