简体   繁体   English

Jenkins 运行 Maven 作业时的多配置传递参数

[英]Jenkins multi configuration passing parameters when running Maven job

I'm trying to set up a Jenkins multi configuration job for the selenium tests of my project that runs against multiple browsers.我正在尝试为针对多个浏览器运行的项目的 selenium 测试设置 Jenkins 多配置作业。 I checked the different options and the multi configuration job seems to be a good fit, but I cannot make maven pass the parameters correctly to maven.我检查了不同的选项,多配置作业似乎很合适,但我无法让 maven 将参数正确传递给 maven。

I have a few parameters I need to pass to maven, mainly browserName and appDomain, and also a Profile to run the tests.我有几个参数需要传递给 maven,主要是 browserName 和 appDomain,还有一个配置文件来运行测试。 To configure the job I do the following:要配置作业,我执行以下操作:

  • Define the SVN repository from where the code will be checked out.定义将从中签出代码的 SVN 存储库。
  • Set up browserName as a user define axis, with values FIREFOX, CHROME, IE.将 browserName 设置为用户定义轴,值为 FIREFOX、CHROME、IE。
  • Create a build step of type "Invoke top-level Maven targets", and here's where I get the problems.创建“调用顶级 Maven 目标”类型的构建步骤,这就是我遇到问题的地方。 The configuration of this part is different from other job types, usually there's a field called Goals and Options where to put everything, but in this case is divided in different fields.这部分的配置与其他作业类型不同,通常会有一个名为Goals和Options的字段来放置所有内容,但在本例中分为不同的字段。 So I don't know where exactly put the properties and the profile.所以我不知道属性和配置文件到底放在哪里。

    a) The logical thing, I put the goals in Goals field and the parameters and options in the properties field, like in the image: a) 合乎逻辑的事情,我将目标放在目标字段中,将参数和选项放在属性字段中,如图所示:

第一个案例

In this case the job runs normally without executing the tests, because the profile is not executed.在这种情况下,作业正常运行而不执行测试,因为配置文件未执行。

b) If I put just the profile in the Goals field, the maven call in the log is: b) 如果我只将配置文件放在目标字段中,则日志中的 maven 调用是:

/opt/apache-maven-2.2.1/bin/mvn -DbrowserName=CHROME "-D-Dappdomain=0 -Dtestenv=test  -Drc=true -DsuiteXmlFile=testOne.xml -U -Dapp.instance.key=jenkins -Denv=default" clean verify -Pwebtests

And the exception is:例外是:

[INFO] [enforcer:enforce {execution: enforce-property}]
[WARNING] Rule 0: org.apache.maven.plugins.enforcer.RequireProperty failed with message:
You must pass the appdomain as parameter! Example: -Dappdomain=20
[WARNING] Rule 1: org.apache.maven.plugins.enforcer.RequireProperty failed with message:
You must pass the test environment as parameter! Example: -Dtestenv=beta

So is not getting the properties所以没有得到属性

c) Finally, if I put everything in the goals field, I get the following exception: c) 最后,如果我将所有内容都放在目标字段中,则会出现以下异常:

[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] One or more required plugin parameters are invalid/missing for 'property:merge'

[0] Inside the definition for plugin 'property-maven-plugin' specify the following:

<configuration>
  ...
  <environment>VALUE</environment>
</configuration>
-OR-
on the command line, specify: '-Denv=VALUE'

I tried with a normal and parametrized job and works perfectly...我尝试了一个正常的参数化工作并且完美地工作......

Jenkins version is: 1454 and Maven is 2.2.1 Jenkins 版本是:1454 和 Maven 是 2.2.1

I found out that the Jenkins machine wasn't properly configured.我发现 Jenkins 机器没有正确配置。 I tried in another instance and was all good with the following configuration:我在另一个实例中尝试过,并且使用以下配置都很好:

-Goals: clean verify Pwebtests
-Paramenters: (properties file format) 
appDomain=0 
testenv=test 
env=default
....

And as a sidenote, the other jobs were working because they were using the Jenkins Maven plugin, which seems to use java to launch a Hudson class that calls Maven, instead of calling directly the mvn command, which is what happens when a build step of type "Invoke top-level Maven Targets"作为旁注,其他工作之所以有效,是因为他们正在使用 Jenkins Maven 插件,该插件似乎使用 java 来启动调用 Maven 的 Hudson class,而不是直接调用 mvn 命令,这是构建步骤时发生的情况输入“调用顶级 Maven 目标”

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

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