0

I need to use the Variable group in the azure pipeline that links to Azure Key Vault secret. The secret will be used to connect to a sql database.

Is there a way that I can pass/use this variable group to Jmeter.jmx when running it as build in the Azure Pipeline?

This is the template that I used when running the Jmeter.jmx load test file.

https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/test/run-jmeter-load-test?view=azure-devops#open-source

vdatuin
  • 3
  • 2
  • Hi, how the things going now? Does the replace token task can successfully achieve what you want? If yes, you can [accept the answer](https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work) thus other SO users will be able to see whether the solution works. If you are still facing some issues please leave a comment so we can still help you . – Mengdi Liang Sep 17 '19 at 06:36
  • Hi Merlin Liang! Thanks for this solution. Unfortunately, I still can't try it on our end since the ADO admin still hasn't approve the replace token extension. I'm going to accept this as valid answer though. – vdatuin Sep 19 '19 at 13:25
  • No problem. If you have any issue or question about this solution, just free to ask here. I will help you until you execute this successfully. – Mengdi Liang Sep 19 '19 at 13:27

3 Answers3

1

Since there no such option or checkbox in task of pipeline to directly achieve pass variable value to .jmx file, you can use the Replace token task to achieve the Parameter value replaced.

  • Use Azure Key Vault task to download the relevant secrets firstly.

enter image description here

  • Add Replace Token task(note: add this task before test step thus the test step can executed with the .jmx file which has received the value), then specify the target files

enter image description here

  • Then configure the variable in .jmx file with the format #{parameter name}#:

enter image description here

Note: The parameter name which defined in the .jmx file should same with the variable name which in Azure key Vault. Otherwise, the parameter could not get the value from variable.

This is my source files which exists in my agent locally, you can see that the value was passed successfully:

enter image description here

Mengdi Liang
  • 17,577
  • 2
  • 28
  • 35
  • What if we need to run the script locally using JMeter UI (without pipeline), the way parameter `#{parameter name}#` is set would not allow it to run from local, right? – Abhishek Aggarwal Jan 12 '21 at 13:28
  • @AbhishekAggarwal, yes, exactly. The approach I shared above is only available in Azure devops environment as the extension is cloud-based. – Mengdi Liang Jan 13 '21 at 07:41
0

Using linux sed:

Replace a known token variable in file.jmx with 'sed' as follows: In .jmx add a known token to be replaced as: %SERVER_NAME% Replace your token with an environment variable

- script: |
echo "Replace Servername parameter in file.jmx with $ sed "
sed 's/%SERVER_NAME%/server.com/g' file.jmx > new.jmx
# or replace with a global variable
sed 's/%SERVER_NAME%/'$(SERVER_NAME)'/g' file.jmx > new.jmx

Replacing with sed a value in .jmx

0

Using Azure variables:

In file.jmx add your Azure global or pipeline local variables, on this case I add the user_name. In jMeter I suggest add a Config Element > Used Defined Variables and add a variable as:

 Name          | Value
 user_name     | ${__groovy( System.getenv("USER_NAME") )}

In case you are passing secret password add the reference in the variables by using the Property option as

Name           | Value
user_password  | ${__P(USER_PASSWORD)}

Set your variable locally on jMeter > bin path as

   set USER_NAME=rmd_test_4

In your jMeter requests, you should use the variable ${user_name} and ${user_password}. Your Azure command should be the same as if you run them locally in your CLI as follows:

   Locally: jmeter -n -t test_flow.jmx -JUSER_PASSWORD=abc123
   Azure:   jmeter -n -t test_flow.jmx -Juser_pwd=$(RMD_TEST_PASS)

I hope this may help