shell 如何使用多行脚本执行mvn?

whhtz7ly  于 12个月前  发布在  Shell
关注(0)|答案(2)|浏览(151)

我正在一个maven项目中使用JMeter编写测试用例。我想为每个测试用例提供shell和批处理脚本示例,以便其他人可以轻松地尝试这些测试。另一方面,这些脚本是关于如何通过参数配置测试用例的示例。被多行格式化操作系统能够很容易地理解脚本parameteres的重要性,特别是当我有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 - WSL with Hyper上发生

  • 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
xlpyo6sf

xlpyo6sf1#

在jmx之后不应该有任何空间。

mvn clean verify -DjMeterScript=JMXFileName.jmx\
  -Djmeter.url=test.environment.url \
  -Djmeter.port=6080 \
  -Djmeter.protocol=http \
  -Djmeter.debugMode=1 \
  -Djmeter.viaFiddler=1 \

这也将工作

mvn spring-boot:run\
    -DDB_HOST=${DB_HOST} \
    -DDB_PORT=${DB_PORT} \
    -DDB_NAME=${DB_NAME} \
    -DDB_USER=${DB_USER} \
    -DDB_PASSWORD=${DB_PASSWORD} \
9bfwbjaz

9bfwbjaz2#

我也有同样的问题,你应该使用^符号来换行,但也要包含所有参数,并在引号中加上点。我认为你不必在最后一行加上^符号。
在你的例子中,它应该看起来像这样:

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

相关问题