2

How can I get the environment variable from docker file for example I am adding a

ENV URL_PATH="google.com"

in my dockerfile, so can I get the this URL_PATH in my Jmeter.jmx file with the help of User Defined Variable.

On window its working fine with proper {__env(URL_PATH)}

but on docker its not working. How can I solve this problem?

Hash
  • 4,647
  • 5
  • 21
  • 39
Sumit Garg
  • 29
  • 8

2 Answers2

2

You can use the -e option to pass environment variables into the container when running it.

docker run -e URL_PATH=google.com ...

Docs: https://docs.docker.com/engine/reference/run/#env-environment-variables

Yuankun
  • 6,875
  • 3
  • 32
  • 34
  • Is this compatible for Linux +terminal – Sumit Garg Mar 27 '18 at 10:42
  • I think this is for windows, but I am using Linux – Sumit Garg Mar 27 '18 at 10:42
  • Docker Code:- RUN -e URL_PATH=google.com COPY entrypoint.sh / WORKDIR ${JMETER_HOME} COPY sample.jmx ./ RUN ls -l RUN echo $PATH # ENTRYPOINT ["/entrypoint.sh"] CMD jmeter -JJmeter_Result=$Jmeter_Result CMD jmeter -n -t sample.jmx -l sample.csv -e -o sample.html – Sumit Garg Mar 27 '18 at 11:44
  • I am passing in jmeter User Defined Varibale :- {__env(URL_PATH)} ${__env(URL_PATH)} – Sumit Garg Mar 27 '18 at 11:46
  • My Docker File Screenshot :- https://www.dropbox.com/s/05lz2r2jzdd0dz4/Untitled.png?dl=0 can you please check and update me – Sumit Garg Mar 27 '18 at 12:07
1

As far as I can see __env() is a Custom JMeter Function therefore it is not available in vanilla JMeter so the options are in:

  1. Amend your Dockerfile to include downloading of http://repo1.maven.org/maven2/kg/apc/jmeter-plugins-functions/2.0/jmeter-plugins-functions-2.0.jar to "lib/ext". This way you will be able to use __env() function in Docker environment normally. See Make Use of Docker with JMeter - Learn How for example Docker configuration assuming using JMeter with Plugins.

  2. Switch to __groovy() function. Replace all the occurrences of {__env(URL_PATH)} with the following expression:

    ${__groovy(System.getenv('URL_PATH'),)} 
    
Dmitri T
  • 159,985
  • 5
  • 83
  • 133