1

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.

DumbNewbie
  • 159
  • 1
  • 5
  • 21
  • I've also tried various times using ENV and export FOO=whatever && RUN jboss-cli.sh foo.cli but no luck. – DumbNewbie Mar 04 '20 at 13:57
  • 1
    How did you define the FOO var ? Where do you run jboss-cli.sh foo.cli ? In the image build ? In the running container? Please be explicit :) – davidxxx Mar 04 '20 at 15:59
  • FOO is defined and passed in from a Jenkinsfile that uses a groovy shared library, which calls Docker. jboss-cli.sh is called in the Dockerfile that is run by the shared library. I think I don't understand the second question based on my poor answer. – DumbNewbie Mar 04 '20 at 16:52
  • I am running jboss-cli.sh in the image build. I just realized what the second question was asking after power-cycling my brain. – DumbNewbie Mar 04 '20 at 17:02
  • @DumbNewbie, Can you check the answer and mark it done if it solves an issue? – nischay goyal Jun 01 '20 at 12:56

3 Answers3

2

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.

nischay goyal
  • 3,206
  • 12
  • 23
0

you might need to set jboss-cli.xml to <resolve-parameter-values>true<\/resolve-parameter-values>

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

src: https://mirocupak.com/using-environment-variables-in-jboss-cli/

lieven121
  • 41
  • 5
0

These are good hints how to solve the problem, but the sed command does not work this way on Mac. There is a lot of fun with "-i". More information here:

sed command with -i option failing on Mac, but works on Linux

On Mac this worked for me: sed -i "" "s/false</resolve-parameter-values>/true</resolve-parameter-values>/" $JBOSS_HOME/bin/jboss-cli.xml

Unfortunately this way of using sed does not work on RHEL for example.

David Hladky
  • 495
  • 7
  • 14