1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Apache JMeterのテストシナリオから環境変数やシステムプロパティを参照する

Last updated at Posted at 2024-02-09

What's?

タイトルのとおり、Apache JMeterのシナリオから環境変数やシステムプロパティを参照するにはどうしたら?ということで調べてみました。

ユーザー定義変数とBeanShell

環境変数やシステムプロパティは固定値なので、ユーザー定義変数として見るのがよさそうです。

Component Reference / Configuration Elements / User Defined Variables

取得方法は、BeanShellを使うことになりそうです。

Functions and Variables / __BeanShell

つまり、ユーザー定義変数の値に対して環境変数であれば

${__BeanShell(System.getenv("環境変数名"))}

として、システムプロパティであれば

${__BeanShell(System.getProperty("システムプロパティ名"))}

とすればよさそうです。

サンプル

試しに、HTTPリクエストのホスト名とポート番号を変数にして

image.png

これらをそれぞれ環境変数およびシステムプロパティから取得するようにしてみました。

image.png

こうですね。

${__BeanShell(System.getenv("TARGET_HOST"))}
${__BeanShell(System.getProperty("target.port"))}

設定方法ですが、環境変数はまあいいとして、システムプロパティはどうすればいいのかな?と思ったのでヘルプを見て見ます。

$ bin/jmeter -?

-D[システムプロパティ名]=[値]で良さそうです。

        -D, --systemproperty <argument>=<value>
                Define additional system properties

つまり、今回のサンプルならこんな感じですね。

$ TARGET_HOST=localhost bin/jmeter -Dtarget.port=8080

確認環境

$ bin/jmeter --version
WARN StatusConsoleListener The use of package scanning to locate plugins is deprecated and will be removed in a future release
WARN StatusConsoleListener The use of package scanning to locate plugins is deprecated and will be removed in a future release
WARN StatusConsoleListener The use of package scanning to locate plugins is deprecated and will be removed in a future release
WARN StatusConsoleListener The use of package scanning to locate plugins is deprecated and will be removed in a future release
    _    ____   _    ____ _   _ _____       _ __  __ _____ _____ _____ ____
   / \  |  _ \ / \  / ___| | | | ____|     | |  \/  | ____|_   _| ____|  _ \
  / _ \ | |_) / _ \| |   | |_| |  _|    _  | | |\/| |  _|   | | |  _| | |_) |
 / ___ \|  __/ ___ \ |___|  _  | |___  | |_| | |  | | |___  | | | |___|  _ <
/_/   \_\_| /_/   \_\____|_| |_|_____|  \___/|_|  |_|_____| |_| |_____|_| \_\ 5.6.3

Copyright (c) 1999-2024 The Apache Software Foundation

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?