Hi! I am trying to use environment variables with ...
# help
j
Hi! I am trying to use environment variables with the templating engine, so that I can modify an output xml based on an environment variable. This is working for me: in stubs.json "transformers": ["response-template"], "bodyFileName": "my.xml", "transformerParameters": { "newIp": "192.168.1.1" } and in xml file: uri="https://{{parameters.newIp}} Now, I would like to use the value of an environment variable instead of hardcoding the IP in the newIp parameter. I have tried setting the variable in docker compose, but then I get java.util.MissingResourceException error. I have been playing with several combinations of {{systemValue type='ENVIRONMENT' key='SERVER_IP' default='127.0.0.1'}} in payload or stub file, but I get the java error or no substitution is performed. In one case, I got this trace in the output payload: uri="https//[ERROR Access to SERVER_IP is denied] How could I do this? Thanks in advance for your help!
l
If I remember correctly, WireMock restricts the values that can be retrieved from the environment or system properties. If you haven't configured anything then by default the keys you use will have to be named to match the
wiremock.*
regex
You can configure this if you didn't want to use
wiremock
on the front of your keys:
Copy code
--permitted-system-keys: Comma-separated list of regular expressions for names of permitted environment variables and system properties accessible from response templates. Only has any effect when templating is enabled. Defaults to wiremock.*.
j
Right! I changed the variable declaration in docker compose to: - WIREMOCK_SERVER_IP=192.168.1.1 and it works perfectly with this substitution: {{systemValue type='ENVIRONMENT' key='WIREMOCK_SERVER_IP' default='127.0.0.1' Thank you very much!!
🙌 1
l
Excellent. Glad it worked
🙌 1