shell - 如何使用多行脚本执行 mvn?
问题描述
我在一个 Maven 项目中使用 JMeter 编写测试用例。我想为每个测试用例提供 shell 和批处理脚本示例,以便其他人可以轻松地尝试这些测试。另一方面,这些脚本是关于如何通过参数配置测试用例的示例。多行格式的操作系统能够轻松理解脚本参数的重要性,尤其是当我将拥有具有 10 多个参数的脚本时。
以批处理格式执行脚本的 mvn 命令如下所示。批处理格式就像魅力一样。
mvn clean verify -DjMeterScript=JMXFileName.jmx ^
-Djmeter.url=test.environment.url ^
-Djmeter.port=6080 ^
-Djmeter.protocol=http ^
-Djmeter.debugMode=1 ^
-Djmeter.viaFiddler=1 ^
但是,shell 格式不起作用。根据互联网终极知识,多行 shell 脚本的格式应如下所示。
mvn clean verify -DjMeterScript=JMXFileName.jmx \
-Djmeter.url=test.environment.url \
-Djmeter.port=6080 \
-Djmeter.protocol=http \
-Djmeter.debugMode=1 \
-Djmeter.viaFiddler=1 \
./shellScriptName.sh
当我使用包含上述示例的脚本执行脚本时,出现以下错误。
问题是如何正确格式化调用 maven 的 shell 脚本?
更新 - 它只发生在 Windows 10 - 带有 Hyper 的 WSL 上:
- Windows 10 上的 Git bash 运行良好
- Macbook Pro 也可以正常工作
- 使用任何 linux 都可以正常工作
错误信息:
[ERROR] Unknown lifecycle phase "
[ERROR] ". You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>. Available lifecycle phases are: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-clean, clean, post-clean, pre-site, site, post-site, site-deploy. -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/LifecyclePhaseNotFoundException
解决方案
我遇到了同样的问题,您应该使用 ^ 符号来换行,但也要包含所有带引号的参数。我认为您不必在最后一行添加 ^ 符号。
因此,在您的情况下,它应该如下所示:
mvn clean verify -DjMeterScript="JMXFileName.jmx" ^
-D"jmeter.url"="test.environment.url ^
-D"jmeter.port"=6080 ^
-D"jmeter.protocol"=http ^
-D"jmeter.debugMode"=1 ^
-D"jmeter.viaFiddler"=1
推荐阅读
- javascript - 如何在 Ajax 使用的 url 中附加表单数据?
- html - 如何居中翻转图像和文本
- google-apps-script - Apps 脚本插件:如何跟踪管理域安装?
- reactjs - 如何模拟/监视 ReactJS 中在 ref 上调用的 addEventListener 方法?
- python - 当前路径 product/ 与其中任何一个都不匹配
- python - Pandas - 用特定组的平均值替换列中的 NaN
- kubernetes - 使用 Istio 将请求路由到外部服务(Webhooks)
- ruby - Ruby-Heroku 如何创建 procfile
- function - 如何在函数中使用泛型并在 rust 中使用模式匹配?
- google-app-engine - 如何通过 Google App engine Flex 将 Google Cloud SQL 连接到僵尸网络核心应用程序?