Maven auto increment release version - maven

I am working on an initiative to auto increment the X.Y.Z version during the build process. In this case we are not removing the SNAPSHOT suffix (to make it a released version), rather increasing the minor part of the version:
X.Y.Z-SNAPSHOT => X.Y.Z+1-SNAPSHOT
NOT X.Y.Z-SNAPSHOT => X.Y.Z
I cannot use the maven release plugin since it is ONLY capable of cutting off SNAPSHOT suffix to make it released versions. So, I ended up creating a custom script which has the logic to increment versions.
My question here is how can I best implement the following steps:
Check out the pom.xml from perforce.
Run the custom script to increment version.
Commit the pom.xml change if deployment was successful.
I created a maven profile autoversion which partially meets the above needs. Maven first increments the version as part of generate resources phase. However, it ends up deploying the older version of the project.
mvn -Pautoversion clean deploy
<profile>
<id>autoversion</id>
<build>
<plugins>
<plugin>
<artifactId>exec-maven-plugin</artifactId>
<groupId>org.codehaus.mojo</groupId>
<executions>
<execution>
<id>Calculate version</id>
<phase>generate-resources</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>${basedir}/autoincrementversion.sh</executable>
<arguments>
<argument>-bdj</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-scm-plugin</artifactId>
<version>1.9</version>
<executions>
<execution>
<phase>generate-resources</phase>
<goals>
<goal>edit</goal>
<goal>checkin</goal>
</goals>
<configuration>
<username>jenkins</username>
<basedir>./</basedir>
<includes>pom.xml</includes>
<message>Auto increment pom version</message>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
[INFO] ------------------------------------------------------------------------
[INFO] Building project 99.22.8
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- versions-maven-plugin:1.3.1:set (default-cli) # project ---
[INFO] Searching for local aggregator root...
[INFO] Local aggregation root: /opt/project/auto-increment-release
[INFO] Processing com.project
[INFO] Updating project com.project
[INFO] from version 99.22.8 to 99.22.9
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.135s
[INFO] Finished at: Wed Nov 05 23:15:13 PST 2014
[INFO] Final Memory: 11M/152M
[INFO] ------------------------------------------------------------------------
Any pointers to achieve the requirement is highly appreciated.

We are considering to actually use Maven Release Plugin (MRP) in similar situation changing ALL version numbers to something like X.Y.Z.N:
X.Y.Z is semantic part which changes rarely during proper human-guided release
N is incremental part (meaningless except sequence ordering) which MRP is able to increment automatically
Yes, MRP will create two additional commits (with released version and next SNAPSHOT version), but... If your developers make snapshot builds they need X.Y.Z.N-SNAPSHOT versions. And if you want incremental release, you also need X.Y.Z.N too. Hence, the same two commits.
All you may avoid optionally is X.Y.Z.N tagging waiting for X.Y.Z only.

Related

Maven Invoker Plugin not detecting failed test

As part of a root parent pom project, several integration tests have been added to test it on sample projects.
The structure of the project folder is as following:
-root-maven-parent-project
|- src
| |-it
| |-sample-project-test1
| |-sample-project-test2
| |-sample-project-test3
| |-settings.xml
|- pom.xml
The main issue is: although the build of sample-project-test2 is wrongly failing (it should not), the build is SUCCESSFUL for the Invoker plugin and the overall build does not fail.
Here is the concerned maven-invoker-plugin configuration:
<profile>
<id>it-tests</id>
<build>
<plugins>
<!-- Integration tests configuration -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-invoker-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<streamLogs>true</streamLogs>
<goals>
<goal>clean</goal>
<goal>generate-sources</goal>
</goals>
<settingsFile>src/it/settings.xml</settingsFile>
<failIfNoProjects>true</failIfNoProjects>
</configuration>
<executions>
<execution>
<id>integration-test-release</id>
<goals>
<goal>install</goal>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<cloneProjectsTo>${project.build.directory}/its/sample-project-test1</cloneProjectsTo>
<pom>src/it/sample-project-test1/pom.xml</pom>
<properties>
<scmBranch>release-something</scmBranch>
</properties>
</configuration>
</execution>
<execution>
<id>integration-test-hotfix</id>
<goals>
<goal>install</goal>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<cloneProjectsTo>${project.build.directory}/its/sample-project-test2</cloneProjectsTo>
<pom>src/it/sample-project-test2/pom.xml</pom>
<properties>
<scmBranch>hotfix-something</scmBranch>
</properties>
</configuration>
</execution>
<execution>
<id>integration-test-master</id>
<goals>
<goal>install</goal>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<cloneProjectsTo>${project.build.directory}/its/sample-project-test3</cloneProjectsTo>
<pom>src/it/sample-project-test3/pom.xml</pom>
<properties>
<scmBranch>master</scmBranch>
</properties>
</configuration>
</execution>
</plugin>
</plugins>
</build>
</profile>
As you can see, multiple executions are configured because each execution would need its own properties. Each execution is also pointing at its own integration test project and pom.
The build is clearly failing for a specific execution:
[INFO] [INFO] ------------------------------------------------------------------------
[INFO] [INFO] BUILD FAILURE
[INFO] [INFO] ------------------------------------------------------------------------
[INFO] [INFO] Total time: 2.337 s
[INFO] [INFO] Finished at: 2017-07-04T17:35:49+02:00
[INFO] [INFO] Final Memory: 12M/220M
[INFO] [INFO] ------------------------------------------------------------------------
[INFO] [ERROR] Failed to execute goal org.apache.maven.plugins:maven-enforcer-plugin:1.4.1:enforce (enforce-snapshot-management) on project cmp-sample-project-test2: Some Enforcer rules have failed. Look above for specific messages explaining why the rule failed. -> [Help 1]
[INFO] [ERROR]
[INFO] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[INFO] [ERROR] Re-run Maven using the -X switch to enable full debug logging.
[INFO] [ERROR]
[INFO] [ERROR] For more information about the errors and possible solutions, please read the following articles:
[INFO] [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
[INFO] pom.xml .......................................... FAILED (4.1 s)
[INFO] The build exited with code 1. See C:\data\git-repositories\root-maven-parent\target\its\sample-project-test2\build.log for details.
However, at the bottom of the build we see that the verify goal of the maven-invoker-plugin aggregated the results, flagged the concerned test as Passed and made the build SUCCESS:
[INFO]
[INFO] --- maven-invoker-plugin:3.0.0:verify (integration-test-release) # root-maven-parent ---
[INFO] -------------------------------------------------
[INFO] Build Summary:
[INFO] Passed: 1, Failed: 0, Errors: 0, Skipped: 0
[INFO] -------------------------------------------------
[INFO]
[INFO] --- maven-invoker-plugin:3.0.0:verify (integration-test-hotfix) # root-maven-parent ---
[INFO] -------------------------------------------------
[INFO] Build Summary:
[INFO] Passed: 1, Failed: 0, Errors: 0, Skipped: 0
[INFO] -------------------------------------------------
[INFO]
[INFO] --- maven-invoker-plugin:3.0.0:verify (integration-test-master) # root-maven-parent ---
[INFO] -------------------------------------------------
[INFO] Build Summary:
[INFO] Passed: 1, Failed: 0, Errors: 0, Skipped: 0
[INFO] -------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
Moreover, by only running the failing test from command line as:
mvn invoker:integration-test#integration-test-hotfix invoker:verify -Pit-tests
The sub-build of the test project fails, the output is correctly marked as Failed in the test summary, and the build is correctly ending with FAILURE.
Question: why when executing multiple integration tests using the maven-invoker-plugin, although a test is failed, it is marked as Passed in the test summary and the build does not fail, while running only the isolated test everything fails correctly?
Note: no invoker property file is used.
Issue solved with the following explanation, although I think something could be improved in the behavior of the plugin (see below).
The whole maven-invoker-plugin was reduced to the following configuration:
<profile>
<id>it-tests</id>
<build>
<plugins>
<!-- Integration tests configuration -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-invoker-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<streamLogs>true</streamLogs>
<goals>
<goal>clean</goal>
<goal>generate-sources</goal>
</goals>
<settingsFile>src/it/settings.xml</settingsFile>
<failIfNoProjects>true</failIfNoProjects>
<cloneProjectsTo>${project.build.directory}/its</cloneProjectsTo>
</configuration>
<executions>
<execution>
<id>integration-test-release</id>
<goals>
<goal>install</goal>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
Basically: only one plugin execution, instead of an execution per test, which indeed was verbose and non scalable, but forced by the need of having different values for the same property in each integration test. Apparently, this is not possible via pom configuration and only achievable - unless I am not mistaken - via a test.properties file.
Hence, as a complement to the configuration above, I added in each and every integration test project folder a test.properties file with the following content e.g.:
scmBranch=master
De facto replacing what in the pom.xml file was (as part of an execution of the maven-invoker-plugin:
<properties>
<scmBranch>master</scmBranch>
</properties>
This mechanism (single execution of the plugin + test properties file per test folder) fixed the issue, allowing the build to have multiple integration tests each with its own different value for the same property. Hopefully this solution may help troubleshooting similar issues.
Here is the final result from the build correctly aggregating tests and effectively respecting their sub-build output (while before the build was generating 6 Build Summary of Passed: 1 each time, although not correct).
[INFO] --- maven-invoker-plugin:3.0.0:verify (pom-integration-test) # root-maven-parent ---
[INFO] -------------------------------------------------
[INFO] Build Summary:
[INFO] Passed: 6, Failed: 0, Errors: 0, Skipped: 0
[INFO] -------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
However, some questions remain:
Without using the test.properties file, how to achieve the same via pom.xml configuration? Normally, it should only be an alternative, not a mandatory and only possible solution. That's why this is rather a uncomplete feature (a bug?) to me.
Having multiple execution of the plugin results in test summaries at the end of the build which correctly follow the executions order, the number of tests executed (always 1 per execution, in this case), but apparently do not reflect the effective result of each sub-build. Why? This is rather a bug or a misbehavior of the plugin due to an unexpected usage of it, perhaps.
use this configuration :-
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.0</version>
<configuration>
<rules>
<banDuplicateClasses>
<findAllDuplicates>true</findAllDuplicates>
</banDuplicateClasses>
</rules>
<fail>false</fail>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.mojo</groupId>
<artifactId>extra-enforcer-rules</artifactId>
<version>1.0-alpha-1</version>
</dependency>
</dependencies>
</plugin>
for more refer this link :
http://maven.apache.org/enforcer/maven-enforcer-plugin/

Update jenkins selenium plugin to version 3.0.1

I want to update jenkins selenium plugin (latest version: 2.53.1).
I can configure selenium hub and nodes outside of jenkins and run my automated tests with latest browser versions (firefox 51.0.1, chrome 55.0.2883.87) successfully but I just want to use jenkins as hub.
So that's why I'm trying to integrate the newest version of the selenium-server-standalone (3.0.1) into Jenkins but it's not working.
Getting this error messages:
[WARNING] The POM for org.jenkins-ci.tools:maven-hpi-plugin:jar:1.117 is missing, no dependency information available
[WARNING] Failed to build parent project for org.jenkins-ci.plugins:selenium:hpi:2.53.2-SNAPSHOT
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO]Building Jenkins Selenium Plugin 2.53.2-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-hpi-plugin:1.117:validate (default-validate) # selenium ---
[INFO]
[INFO] --- maven-enforcer-plugin:1.3.1:display-info (display-info) # selenium ---
[INFO] Maven Version: 3.3.9
[INFO] JDK Version: 1.8.0_121 normalized as: 1.8.0-121
[INFO] OS Info: Arch: amd64 Family: unix Name: linux Version: 4.4.0-62-generic
[INFO]
[INFO] --- maven-enforcer-plugin:1.3.1:enforce (display-info) # selenium ---
[INFO] Restricted to JDK 1.7 yet org.seleniumhq.selenium:selenium-server-standalone:jar:3.0.1:compile contains org/openqa/selenium/chrome/ChromeDriver.class targeted to JDK 1.8
[WARNING] Rule 2: org.apache.maven.plugins.enforcer.EnforceBytecodeVersion failed with message:
Found Banned Dependency: org.seleniumhq.selenium:selenium-server-standalone:jar:3.0.1
Use 'mvn dependency:tree' to locate the source of the banned dependencies.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO]
------------------------------------------------------------------------
[INFO] Total time: 11.325 s
[INFO] Finished at: 2017-02-15T16:42:25+01:00
[INFO] Final Memory: 62M/1133M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-enforcer-plugin:1.3.1:enforce (display-info) on project selenium: Some Enforcer rules have failed. Look above for specific messages explaining why the rule failed. -> [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/MojoExecutionException
pom.xml of maven project:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>fake</groupId>
<artifactId>fake</artifactId>
<packaging>pom</packaging>
<version>${selenium.version}</version>
<name>fake</name>
<properties>
<selenium.short.version>3.0</selenium.short.version>
<selenium.version>${selenium.short.version}.1</selenium.version>
<htmlunit.driver.version>2.20</htmlunit.driver.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<get
src="http://selenium-release.storage.googleapis.com/${selenium.short.version}/selenium-server-standalone-${selenium.version}.jar"
dest="${project.build.directory}/selenium-server-standalone-${selenium.version}.jar"
verbose="on" usetimestamp="true" />
<get
src="https://github.com/SeleniumHQ/htmlunit-driver/releases/download/${htmlunit.driver.version}/htmlunit-driver-standalone-${htmlunit.driver.version}.jar"
dest="${project.build.directory}/htmlunit-driver-standalone-${htmlunit.driver.version}.jar"
verbose="on" usetimestamp="true" />
</target>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.1</version>
<executions>
<execution>
<id>selenium-server-standalone</id>
<phase>install</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<file>${project.build.directory}/selenium-server-standalone-${selenium.version}.jar</file>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-server-standalone</artifactId>
<version>${selenium.version}</version>
<packaging>jar</packaging>
<localRepositoryPath>local_m2</localRepositoryPath>
</configuration>
</execution>
<execution>
<id>htmlunit-driver-standalone</id>
<phase>install</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<file>${project.build.directory}/htmlunit-driver-standalone-${htmlunit.driver.version}.jar</file>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>htmlunit-driver-standalone</artifactId>
<version>${htmlunit.driver.version}</version>
<packaging>jar</packaging>
<localRepositoryPath>local_m2</localRepositoryPath>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Code : https://github.com/jenkinsci/selenium-plugin
OS: Ubuntu 16.04.2; Eclipse Neon Java IDE ,openjdk version "1.8.0_121"
I've already tried it out with openjdk 1.7 as well but it's still not working.
I'm quite a newbie at this so I appreciate any help. Thanks a lot.
The root cause is simple : The Jenkins plugin's parent pom enforces by default to JDK7. Selenium libraries have moved on to using JDK8. That explains the error message arising from the enforcer plugin.
Here's how the enforcer plugin has been configured in the parent pom
<java.level>7</java.level>
<enforceBytecodeVersion>
<maxJdkVersion>1.${java.level}</maxJdkVersion>
<ignoredScopes>
<ignoredScope>test</ignoredScope>
</ignoredScopes>
<excludes>
<!-- Makes no sense to check core itself: -->
<exclude>org.jenkins-ci.main:jenkins-core</exclude>
<exclude>org.jenkins-ci.main:cli</exclude>
<exclude>org.jenkins-ci.main:jenkins-test-harness</exclude>
<!-- findbugs dep managed to provided and optional so is not shipped and missing annotations ok -->
<exclude>com.google.code.findbugs:annotations</exclude>
</excludes>
</enforceBytecodeVersion>
To fix this, you have two options [ I have never tried this, but its something that you can try and see if it helps ] (Both these options I am suggesting based on the recommendations from your parent pom itself )
Try passing the JVM argument -Djava.level=8 when you build the code.
Add an entry such as below to your pom file (This will cause enforcer plugin to perhaps ignore only the selenium libraries)
maven-enforcer-plugin
display-info
org.seleniumhq.selenium:selenium-java::jar:compile
org.seleniumhq.selenium:selenium-server::jar:compile
Hope that helps!
update
I spent more time looking at this and realised that moving over to selenium 3.0.1 for this plug-in was not very straight forward. I have tried doing the changes and raised a pull request for the same. You can take a look at the PR and see if that helps.
PS : I still have 3 tests failing in the PR. I haven't figured out how to get them to pass. But the PR should help you get started. You can directly checkout my branch and try building from there.

Jenkins + selenium tests with failsafe plugin

I have a Jenkins platform which calls maven to make unit tests (with surefire plugin) and integration tests (with failsafe plugin). When there is an error in the integration tests, Jenkins considers the build as successfull. Is this behavior normal? I'd prefer it considers the build as unstable. More generally, do you know how Jenkins read and interprets the result of the build to consider a build as successfull or unstable? I read somewhere on the net that the failsafe reports must be redirected to the surefire report path. I did id but the problem is still here.
pom.xml :
[...]
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.10</version>
<configuration>
<disableXmlReport>false</disableXmlReport>
</configuration>
<executions>
<execution>
<id>default-test</id>
<phase>test</phase>
<configuration>
<includes>
<include>**/tests/**</include>
</includes>
<excludes>
<exclude>**/testsIntegration/**</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.7.2</version>
<configuration>
<disableXmlReport>false</disableXmlReport>
<reportsDirectory>${basedir}/target/surefire-reports</reportsDirectory>
<includes>
<include>com/acelys/conventionsJuridiques/*.java</include>
<!-- ... inclure les tests Selenium -->
</includes>
</configuration>
<executions>
<execution>
<id>integration-test</id>
<phase>integration-test</phase>
<goals>
<goal>integration-test</goal>
</goals>
<configuration>
<includes>
<include>**/testsIntegration/**</include>
</includes>
<excludes>
<exclude>**/tests/**</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
[...]
output of jenkins :
[...]
mojoStarted org.apache.maven.plugins:maven-failsafe-plugin:2.7.2(integration-test)
[INFO]
[INFO] --- maven-failsafe-plugin:2.7.2:integration-test (integration-test) # BaseContrats ---
[INFO] Failsafe report directory: C:\jenkins_home\workspace\Base Contrats EXT JS MAVEN\target\surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running com.acelys.conventionsJuridiques.testsIntegration.connexion.TestConnexion
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 23.971 sec <<< FAILURE!
Results :
Failed tests:
testHomePage(com.acelys.conventionsJuridiques.testsIntegration.connexion.TestConnexion)
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
mojoSucceeded org.apache.maven.plugins:maven-failsafe-plugin:2.7.2(integration-test)
mojoStarted org.apache.tomcat.maven:tomcat6-maven-plugin:2.1-SNAPSHOT(tomcat-shutdown)
[INFO]
[INFO] --- tomcat6-maven-plugin:2.1-SNAPSHOT:shutdown (tomcat-shutdown) # BaseContrats ---
25 févr. 2013 09:32:08 org.apache.coyote.http11.Http11Protocol destroy
INFO: Stopping Coyote HTTP/1.1 on http-8080
25 févr. 2013 09:32:08 org.apache.catalina.core.ApplicationContext log
INFO: Closing Spring root WebApplicationContext
25 févr. 2013 09:32:08 org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc
mojoSucceeded org.apache.tomcat.maven:tomcat6-maven-plugin:2.1-SNAPSHOT(tomcat-shutdown)
projectSucceeded BaseContrats:BaseContrats:1.0-SNAPSHOT
sessionEnded
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2:07.408s
[INFO] Finished at: Mon Feb 25 09:32:08 CET 2013
[INFO] Final Memory: 13M/51M
[INFO] ------------------------------------------------------------------------
Projects to build: [MavenProject: BaseContrats:BaseContrats:1.0-SNAPSHOT # C:\jenkins_home\workspace\Base Contrats EXT JS MAVEN\pom.xml]
[JENKINS] Archiving C:\jenkins_home\workspace\Base Contrats EXT JS MAVEN\pom.xml to C:\jenkins_home\jobs\Base Contrats EXT JS MAVEN\modules\BaseContrats$BaseContrats\builds\2013-02-25_09-29-58\archive\BaseContrats\BaseContrats\1.0-SNAPSHOT\BaseContrats-1.0-SNAPSHOT.pom
[JENKINS] Archiving C:\jenkins_home\workspace\Base Contrats EXT JS MAVEN\target\ConventionsJuridiques.war to C:\jenkins_home\jobs\Base Contrats EXT JS MAVEN\modules\BaseContrats$BaseContrats\builds\2013-02-25_09-29-58\archive\BaseContrats\BaseContrats\1.0-SNAPSHOT\BaseContrats-1.0-SNAPSHOT.war
channel stopped
Finished: SUCCESS
According to the documentation:
failsafe:verify verifies that the integration tests of an application passed.
You need to add the goal to the maven-failsafe-plugin execution:
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
This will allow Jenkins to interpret the test results and mark the build as unstable.
You can see that maven finished with SUCCESS. This will have Jenkins also finish with success.
To mark build as unstable, you need a post build action that will analyse your test results and mark build as failed or unstable. I suggest you search for more details on Jenkins post build actions for processing the test results and marking build as needed.
Hope this helps.
Under the post build actions the Publish JUnit test result report changes the report XML's to search for.
The assumption is the standard surefire and failsafe plugin output directories are used.
changes to
You should add a step in your build : "publish Junit report"
You will have graph showing all your test result, but it will also set the correct build result if tests are failing.
As said by https://stackoverflow.com/users/709863/stephane-piette:
Add a post build action 'Publish Performance test result report'. This action is provided by the plugin named 'Performance plugin'. You probably do not have this plugin installed, which is why it does not exist in the list.
The goal "integration-test" of the failsafe plugin won't mark the build as error when tests fail.
You have to add the goal "verify" to run after "integration-test" in the plugin execution. This will look for errors or failures and mark the build as "error". Then Jenkins will see that Maven did not succeed.
You have to set the plugin's configuration so that the build fails upon failed test(s):
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
....
<configuration>
<testFailureIgnore>false</testFailureIgnore>
</configuration>
<executions>
....
</executions>
</plugin>

maven-deploy-plugin Ignores Version Number?

I am new to Maven, and I am try to deploy my project as a war, and as a jar. I would love to split the project to do the same, but it is too large for simple me to do in a reasonable time.
I found maven deploy additional jar file, which suggested I add some plugins.
The install plugin works great
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<packaging>jar</packaging>
<artifactId>${project.artifactId}</artifactId>
<groupId>${project.groupId}</groupId>
<version>SNAPSHOT</version>
<file>
${project.build.directory}/${project.artifactId}-SNAPSHOT.jar
</file>
</configuration>
</execution>
</executions>
</plugin>
Here is the output:
[INFO] [install:install-file {execution: default}]
[INFO] Installing C:\Server\example\code\server\my-project\target\my-project-SNAPSHOT.jar to C:\Users\Kyle\.m2\repository\com\example\main-project\my-project\SNAPSHOT\my-project-SNAPSHOT.jar
The problem is with the maven-deploy-plugin. It seems to ignore the SNAPSHOT version I am forcing it to use:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<executions>
<execution>
<phase>deploy</phase>
<goals>
<goal>deploy-file</goal>
</goals>
<configuration>
<packaging>jar</packaging>
<generatePom>true</generatePom>
<url>${project.distributionManagement.snapshotRepository.url}</url>
<artifactId>${project.artifactId}</artifactId>
<groupId>${project.groupId}</groupId>
<version>SNAPSHOT</version>
<!--${project.version}!="SNAPSHOT" for some reason-->
<file>${project.build.directory}/${project.artifactId}-SNAPSHOT.jar</file>
</configuration>
</execution>
</executions>
</plugin>
Seems to use some other version number (YYYYMMDD.HHmmSS-#)
[INFO] [deploy:deploy-file {execution: default}]
[INFO] Retrieving previous build number from remote-repository
Uploading: http://build.example.biz:8081/artifactory/libs-snapshots-local/com/example/main-project/my-project/SNAPSHOT/my-project-20120625.161551-2.jar
42993K uploaded (my-project-20120625.161551-2.jar)
What am I doing wrong?
One thing i observed is that you are using the version SNAPSHOT without any kind of preceding numbers like:
1.0.0-SNAPSHOT
or at least:
1-SNAPSHOT
You are just using SNAPSHOT this does not make sense, cause of which development line you are talking in this case.
The other thing is that a SNAPSHOT (assuming you are using it in the right way) in Maven is an artifact where a timestamp will be put instead of the SNAPSHOT. That's the way to make it possible having multiple SNAPSHOT being released but make them distinguishable.
So the thing you've showed in your output is exactly what Maven makes out of the SNAPSHOT:
[INFO] [deploy:deploy-file {execution: default}]
[INFO] Retrieving previous build number from remote-repository
Uploading: http://build.example.biz:8081/artifactory/libs-snapshots-local/com/example/main-project/my-project/SNAPSHOT/my-project-20120625.161551-2.jar
42993K uploaded (my-project-20120625.161551-2.jar)
In the respective remote repository there is a http://build.example.biz:8081/artifactory/libs-snapshots-local/com/example/main-project/my-project/SNAPSHOT/maven-metadata.xml. If you have a look at it, you will see that the latest timestamp is mapped to your respective SNAPSHOT. This is typical behavior under both Maven 2 and 3. I believe it's the default behavior under Maven 3 to use timestamped SNAPSHOT-s.
When you try downloading the artifact via Maven, I believe it will resolve it correctly for you, so you shouldn't really be alarmed.

failsafe plugin won't run on one project but will run on another -- why?

This is driving me insane. The Maven failsafe plugin will not run on my project. If I run mvn verify only surefire runs. If I type mvn failsafe:verify it fails with the following error:
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Simulation Experiment Server 1.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-failsafe-plugin:2.11:verify (default-cli) # experiment-server ---
[INFO] Failsafe report directory: C:\IdeaProjects\experiment_server\target\failsafe-reports
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.551s
[INFO] Finished at: Fri Mar 30 11:24:58 GMT-06:00 2012
[INFO] Final Memory: 5M/15M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-failsafe-plugin:2.11:verify (default-cli) on project experiment-server: C:\IdeaProjects\experiment_server\target\failsafe-reports\failsafe-summary.xml (The system cannot find the path specified) -> [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/MojoExecutionException
It's complaining about not finding failsafe-summary.xml. But this should be created by the plugin. And the plugin works fine (and creates the failsafe-summary.xml file if I run run Antonio Goncalves wonderful Arquillian example project.
So I copied the exact plugin information Antonio uses, and it still won't run on my project. I've modelled my POM to be exactly like his (except without a parent pom) -- something must be going wrong, I just don't know what. Why will failsafe run on his project but not mine??
Here is my failsafe pom.xml entry, which is taken right from his, and is the same as the one on the failsafe usaages site):
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${version.maven.failsafe.plugin}</version>
<configuration>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
Thanks for any help, this is driving me insane.
UPDATE Okay, I seem to have gotten the cannot find failsafe-summary.xml problem fixed -- I change my directory from experiment_server to experiment-server. I guess that messes up failsafe.
But, I'm still having trouble getting failsafe to run from the command mvn verify or mvn integration-test. Both those commands call surefire instead of failsafe. I can now run failsafe directly by using the command: mvn failsafe:integration-test, but shouldn't failsafe automatically run with mvn verify? My mvn help:effective-pom shows that failsafe is there, so that's not the problem... Any ideas?
Take a look at the failsafe docs for the test names failsafe expects by default:
<includes>
<include>**/IT*.java</include>
<include>**/*IT.java</include>
<include>**/*ITCase.java</include>
</includes>
Are your tests named following one of these patterns? If not, try defining the <includes> element in the plugin configuration. Or change your test name(s) to fit the default pattern.
Okay, now that we've verified the test class names - typically when I add executions to plugin config I do it something like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${version.maven.failsafe.plugin}</version>
<configuration>
</configuration>
<executions>
<execution>
<id>failsafe-integration-tests</id>
<phase>integration-test</phase>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
<execution>
<id>failsafe-verify</id>
<phase>verify</phase>
<goals>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
This explicitly binds the failsafe plugin goals you want to run to the correct phases of the build lifecycle. I believe the surefire plugin is bound to the test lifecycle phase by default (for a jar, war, & ejb anyway), but nothing is bound to integration-test or verify.
Here I will share my 2 cents. I had same issue and solution above didn't solve my problem.
I had maven-failsafe-plugin encapsulated in pluginManagement tag. I noticed to move it out into plugins tag instead when I saw this doc in the 4.0.0 maven schema:
Default plugin information to be made available for reference by
projects derived from this one. This plugin configuration will not
be resolved or bound to the lifecycle unless referenced. Any local
configuration for a given plugin will override the plugin's entire
definition here.
Hopefully this additional info. solves more ppl's problem like myself.
For me it worked only after I added the "default" includes.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.15</version>
<configuration>
<includes>
<include>**/IT*.java</include>
<include>**/*IT.java</include>
<include>**/*ITCase.java</include>
<include>**/IntegrationTest*.java</include>
</includes>
</configuration>
<executions>
<execution>
<id>failsafe-integration-tests</id>
<phase>integration-test</phase>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
<execution>
<id>failsafe-verify</id>
<phase>verify</phase>
<goals>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
If you are running 2.12.2 version of the failsafe plugin, this is normal. Switch to a previous version. It seem 2.13 is not available yet.
Jira link

Resources