简体   繁体   中英

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. 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.

I have a few parameters I need to pass to maven, mainly browserName and appDomain, and also a Profile to run the tests. To configure the job I do the following:

  • Define the SVN repository from where the code will be checked out.
  • Set up browserName as a user define axis, with values FIREFOX, CHROME, IE.
  • Create a build step of type "Invoke top-level Maven targets", and here's where I get the problems. 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. 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:

第一个案例

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:

/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:

[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

I found out that the Jenkins machine wasn't properly configured. 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"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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