通过 taurus 命令行参数动态添加 'Notes'
Adding 'Notes' dynamically through taurus command line arguments
我正在使用 blazemeter/taurus:1.13.2
Docker 图像和 blazemeter 报告模块来执行测试。
是否可以通过 taurus 命令行为 BlazeMeter 上的 "Notes" 字段传递值?我已经成功传递了其他值,例如:
-o modules.blazemeter.report-name="${report_name}"
我希望传入 "Notes" 时只需要类似的东西。我试过:
-o modules.blazemeter.notes="${notes}"
但运气不好。
这是我的 运行 完整命令行脚本:
#!/bin/bash
api_token=
timestamp=`date +%s`
report_name="`hostname`_`git log --format='%h' -n 1`_taurus-jmeter_${timestamp}"
notes="testing use of notes through taurus command line args"
artifacts_dir="artifacts/${timestamp}"
docker run -t --rm -v `pwd`:/bzt-configs -v `pwd`/artifacts:/tmp/artifacts blazemeter/taurus:1.13.2 taurus.yml -o settings.artifacts-dir="${artifacts_dir}" -o modules.blazemeter.report-name="${report_name}" -o modules.blazemeter.notes="${notes}" -o modules.blazemeter.token="${api_token}"
使用 JMeter,您可以使用可以放入 JSR223 Sampler inside setup Thread Group 中的代码
或者你可以使用 Shell Exec.
Java 中的代码:
URL url = new URL("https://a.blazemeter.com:443/api/v4/masters/" + masterId);
HttpURL连接 conn = null;
尝试 {
conn = (HttpURL连接) url.openConnection();
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/json");
conn.setDoInput(真);
conn.setDoOutput(真);
/* We use the API Key and API Secret as Basic Authentication */
String usernameColonPassword = "" + X_GlobalVariables.BZM_API_KEY + ":" + X_GlobalVariables.BZM_API_SECRET + "";
String basicAuthPayload = "Basic " + Base64.getEncoder().encodeToString(usernameColonPassword.getBytes());
// Include the HTTP Basic Authentication payload
conn.addRequestProperty("Authorization", basicAuthPayload);
//Create JSONObject here
JSONObject jsonParam = new JSONObject();
jsonParam.put("note", "Service Version: " + serviceVersion + "\nGateway Version: " + gatewayVersion + "");
try (OutputStreamWriter out = new OutputStreamWriter(conn.getOutputStream())) {
out.write(jsonParam.toString());
}
/* Check here for a OK (200) response */
if (conn.getResponseCode() != 200) {
throw new RuntimeException("Failed : HTTP error code : "
+ conn.getResponseCode());
}
/* Release the connection */
} finally {
if (conn != null) {
conn.disconnect();
}
}
来源:
我正在使用 blazemeter/taurus:1.13.2
Docker 图像和 blazemeter 报告模块来执行测试。
是否可以通过 taurus 命令行为 BlazeMeter 上的 "Notes" 字段传递值?我已经成功传递了其他值,例如:
-o modules.blazemeter.report-name="${report_name}"
我希望传入 "Notes" 时只需要类似的东西。我试过:
-o modules.blazemeter.notes="${notes}"
但运气不好。
这是我的 运行 完整命令行脚本:
#!/bin/bash
api_token=
timestamp=`date +%s`
report_name="`hostname`_`git log --format='%h' -n 1`_taurus-jmeter_${timestamp}"
notes="testing use of notes through taurus command line args"
artifacts_dir="artifacts/${timestamp}"
docker run -t --rm -v `pwd`:/bzt-configs -v `pwd`/artifacts:/tmp/artifacts blazemeter/taurus:1.13.2 taurus.yml -o settings.artifacts-dir="${artifacts_dir}" -o modules.blazemeter.report-name="${report_name}" -o modules.blazemeter.notes="${notes}" -o modules.blazemeter.token="${api_token}"
使用 JMeter,您可以使用可以放入 JSR223 Sampler inside setup Thread Group 中的代码 或者你可以使用 Shell Exec.
Java 中的代码: URL url = new URL("https://a.blazemeter.com:443/api/v4/masters/" + masterId); HttpURL连接 conn = null; 尝试 { conn = (HttpURL连接) url.openConnection(); conn.setRequestMethod("POST"); conn.setRequestProperty("Content-Type", "application/json"); conn.setDoInput(真); conn.setDoOutput(真);
/* We use the API Key and API Secret as Basic Authentication */
String usernameColonPassword = "" + X_GlobalVariables.BZM_API_KEY + ":" + X_GlobalVariables.BZM_API_SECRET + "";
String basicAuthPayload = "Basic " + Base64.getEncoder().encodeToString(usernameColonPassword.getBytes());
// Include the HTTP Basic Authentication payload
conn.addRequestProperty("Authorization", basicAuthPayload);
//Create JSONObject here
JSONObject jsonParam = new JSONObject();
jsonParam.put("note", "Service Version: " + serviceVersion + "\nGateway Version: " + gatewayVersion + "");
try (OutputStreamWriter out = new OutputStreamWriter(conn.getOutputStream())) {
out.write(jsonParam.toString());
}
/* Check here for a OK (200) response */
if (conn.getResponseCode() != 200) {
throw new RuntimeException("Failed : HTTP error code : "
+ conn.getResponseCode());
}
/* Release the connection */
} finally {
if (conn != null) {
conn.disconnect();
}
}
来源: