简体   繁体   English

Jenkinsfile没有将参数传递给Maven

[英]Jenkinsfile not passing parameter to Maven

When I launch a build with parameters, I have this 'choice parameter' named "modeDebug"; 当我启动带有参数的构建时,我有一个名为“ modeDebug”的“选择参数”。 the choice can be "true" or "false" (I did not choose the boolean type because I'll add more options some day). 选择可以是“ true”或“ false”(我没有选择布尔类型,因为有一天我会添加更多选项)。 I need to use this parameter in my Java code but, for some reason, it's not retrieved. 我需要在Java代码中使用此参数,但是由于某些原因,无法检索到该参数。

I have this step in my Jenkinsfile in order to run the tests with parameters: 我在Jenkinsfile中有此步骤,以便使用参数运行测试:

sh 'mvn -gs "$MAVEN_SETTINGS" -Dta.test.suite="{\\"filter\\":\\"'+newTestList+'\\",\\"param\\":{\\"env.devEnv\\":\\"${environnement}\\",\\"env.browser\\":\\"${browser}\\",\\"env.modeDebug\\":\\"${modeDebug}\\"}}"
-Denv.devEnv="${environnement}"
-Denv.browser="${browser}"
-Denv.modeDebug="${modeDebug}"
-Dlog4j.configurationFile="${log4j2ConfigurationFile}"
-Dstatus.update.events.url="${notificationURL}"
-Dsquash.ta.external.id="${externalJobId}" -Djobname="${JOB_NAME}"
-Dhostname="${HOSTNAME}" -Dsquash.ta.conf.file="taLinkConf.properties"
-Dta.tmcallback.reportbaseurl="${JENKINS_URL}job"
-Dta.tmcallback.jobexecutionid="${BUILD_NUMBER}"
-Dta.tmcallback.reportname=Squash_TA_HTML_Report
-Dta.delete.json.file=true squash-ta:"${operation}"'

Then, in my code, I call some of these Maven parameters... 然后,在我的代码中,我调用其中一些Maven参数...

protected String getScreenshotIfFail = java.lang.System.getProperty("env.modeDebug");
protected String devEnv    = java.lang.System.getProperty("env.devEnv");
protected String browser   = java.lang.System.getProperty("env.browser");

String devEnv and browser get populated but not ggetScreenshotIfFail! 会填充字符串devEnv和浏览器,但不会填充ggetScreenshotIfFail!

Notes : In my Jenkinsfile, echo "${modeDebug}" outputs "true" or "false". 注意 :在我的Jenkins文件中, echo "${modeDebug}"输出“ true”或“ false”。 This part is working. 这部分正在工作。
In my code when the tests are run via Jenkins, System.out.println(getScreenshotIfFail); 在我的代码中,当通过Jenkins运行测试时, System.out.println(getScreenshotIfFail); outputs "null". 输出“ null”。
In my IDE, I run the following command with success (getScreenshotIfFail is correctly populated): 在我的IDE中,我成功运行了以下命令(正确填充了getScreenshotIfFail):

-Denv.modeDebug=true -Denv.devEnv=qualif -Denv.browser=chrome -Dlog4j.configurationFile=src/log4j2.xml -Dta.test.suite=squash/**.ta squash-ta:run

Any idea? 任何想法? Thanks! 谢谢!

RTM - String interpolation . RTM- 字符串插值

sh 'mvn ...'
   ^
  that single quote should be double quote.

And of course you'll have to change many other quotes in your string. 当然,您必须在字符串中更改许多其他引号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM