How can I pass a variable group in Jmeter using Azure Pipeline?

后端 未结 3 1065
离开以前
离开以前 2020-12-04 04:26

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 th

相关标签:
3条回答
  • 2020-12-04 04:37

    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.

    • 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

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

    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:

    0 讨论(0)
  • 2020-12-04 04:40

    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 讨论(0)
  • 2020-12-04 04:52

    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

    0 讨论(0)
提交回复
热议问题