Jenkins multi configuration passing parameters when running Maven job - maven

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"

Related

Pass a file as a property while calling a maven goal in Jenkins v2.263.1

I am migrating all my jobs from Jenkins v1.651.3 to Jenkins v2.263.1.
Currently I am passing a file stored in my Linux server as a property under Invoke top-level maven targets build step in Jenkins.
e.g. property.a=/home/user1/props/a.properties and property.b=/home/user1/props/b.properties
In Jenkins v2.263.1, I am running all my jobs in a docker container which is created dynamically.
Where and how can I store this file so that I can pass this as a property to maven build like -Dproperty.a=/home/user1/props/a.properties and -Dproperty.b=/home/user1/props/b.properties
I tried adding these files in Managed Files section under Manage Jenkins option and passing these as -Dproperty.a=a.properties to maven build through Jenkinsfile, however, it did not work. Not sure if it's the right way.
Please let me now if there's a way to handle this.
Thanks in advance!

How to set name of the artifacts produced from Gradle to values passed from Jenkins pipeline

I am trying to setup a Jenkins pipeline to trigger builds using gradle for multiple environments.My requirement is that the artifacts produced when I run gradlew clean build should produce artifacts with name indicating the environment for which the pipeline was run. Example my-application-dev.jar
The value of the environment would be selected by the user when build will be triggered.
What is the optimal way to achieve this ? Does build allow to configure any such property via command line or do I need to define a task in my build.gradle and define properties within that task for which I will pass value from command line
There are basically two ways.
The first one is to pass these naming-relevant pieces of information to the gradlew process, e.g. via -D or -P properties.
Then you need the Gradle build to be aware of these parameters and craft the artifact names it produces accordingly.
The second one is arguably better and more contained. You simply rename the artifacts produced by the gradlew command after it completes, in the Jenkinsfile. This works well if the pipeline decides what to do with these artifacts (e.g. publish to a repository) as opposed to the gradle script doing it (in which case you would most likely be better off using the first method).

What is the TestNG XML report pattern for Jenkins when using Maven with surefire?

I'm using TestNG Results Plugin.
I defined TestNG XML report pattern as: **\target\surefire-reports\testng-results.xml
I'm getting this error:
TestNG Reports Processing: START
Looking for TestNG results report in workspace using pattern: **\target\surefire-reports\testng-results.xml
Did not find any matching files.
What should be the correct pattern?
I just fixed this problem!
It's because that the current directory was changed to the default Jenkins workspace, something like '/Users/Shared/Jenkins/Home/workspace/your_project_name' when it ran!!
You will find it yourself if you add shell command 'pwd' before Post-build Actions in the Configuration of your project in Jenkins.
You just need configure your project in General -> Advanced... -> Use custom workspace, and fill in the full path of your project, and it will work!!!
The following pattern works for me: **/target/surefire-reports/*.xml
Also ensure that the default listeners are not disabled in your surefire configuration to ensure that surefire creates the xml reports for ReoprtNG/TestNG. Until I removed the disabling of default listeners I got the same error.

Generate SQL-scheme and copy it to include to WAR-file: problem with plugins' dependencies

Before running integration tests I need to setup database. This include generating SQL-scheme (based on JPA-annotations), save it to file and copy it with other resources to directory which later will be used for creating war file (which will be deployed to Jetty).
So, I use following hibernate3-maven-plugin configuration for generating SQL-scheme: http://pastebin.ubuntu.com/606229/
To copy resulting hsql-scheme.sql from src/env/test/WEB-INF/classes to target/ where it will be packaged to WAR-file I use following:
http://pastebin.ubuntu.com/606230/
But when I run mvn verify -P test (yes, all these code inside separate profile) I've got: http://pastebin.ubuntu.com/606231/
As you can see hibernate3:hbm2ddl does not generate any SQL-scheme and resulting file is empty (in other case we will see it on console also). And this is a problem.
The root of problem (as I understand) is because hibernate3:hbm2ddl invokes the execution of the lifecycle phase process-resources prior to executing itself.
Thanks in advance!
This question helped me to fix schema' creation:
call hibernate3:hbm2ddl at prepare-package phase instead of generate-resources
put result of hibernate3:hbm2ddl directly to target/${build.finalName}/WEB-INF/classes
So, now I still have hibernate3:hbm2ddl invokes the execution of the lifecycle phase process-resources prior to executing itself warning, but file target/${build.finalName}/WEB-INF/classes/hsql-scheme.sql not empty as before.

Hudson jobs won't call javac?

I have just set up Hudson on my server. For some reason, my build will not call javac to compile my builds...? I have set the path to the JDK in the Manage Hudson area, and it seems to recognise it (doesn't give me a warning). Is there something else I'm supposed to do?
Here's a sample console output of one of my jobs (note how javac isn't called at all):
Started by user admin
Checking out
svn+ssh://myhost.com/Project1
A /src/Program.java
A build.xml
U
At revision 119
no change for
svn+ssh://myhost.com/Project1 since
the previous build
Finished: SUCCESS
You need to set the ant-target for your build.
Since this is a netbeans project you should have ant target like: compile, default etc?
One or more of these build target must be set in your job on hudson under the configuration menu. I think the field is called "Targets"
Some information on configuring ant in hudson: http://testinfected.blogspot.com/2009/01/hudson-default-anth.html

Resources