- Build
- JUnit-Test
- Deployment to JBoss
So I tried to use the Artifacts* which will be generated by the first "Build"-Job to run the following "JUnit-Test"-Job. Everything looked fine - copying the artifacts, running tests - till the end, but than the build faild.
The following error occured:
[ERROR] Failed to execute goal org.codehaus.mojo:buildnumber-maven-plugin:1.2:create (default) on project presentation-war: Cannot get the revision information from the scm repository :
[ERROR] Exception while executing SCM command. svn: E155007: '/var/lib/jenkins/jobs/MT-Server_test-only/workspace/presentation-war' is not a working copy
The problem seems to be the Buildnumber-Plugin, which tried to get the revision information of the SVN workingcopy. But while copying the artifacts to the workspace for the "JUnit-Test"-Job these information get lost cause it is not longer a workingcopy.
We use this plugin to generate a unique identifier which will be shown in the frontpage of our webapplication to identify the currently deployed revision.
Solution:
So far, for our "JUnit-Test"-Job we do not need to update these revision-information so I searched for a solution to ignore this step at the "JUnit-Test"-Job.
The easiest way to get rid of this problem seems to deactivate the "buildnumber-maven-plugin" when run the Job.
The difficult was that all the other jobs do need these information so I was looking for a solution which does not affecting these.
So now lets get to my solution:
1. I modified the "pom.xml" of the project and added a profile like the following:
<project>
<....>
<profiles>
<profile>
<id>buildnumber</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<executions>
<execution>
<id>generate-buildnumber</id>
<phase>validate</phase>
<goals>
<goal>create</goal>
</goals>
<configuration>
<getRevisionOnlyOnce>true</getRevisionOnlyOnce>
<providerImplementations>
<svn>javasvn</svn>
</providerImplementations>
<timestampFormat>{0,date,yyyy-MM-dd HH:mm:ss}</timestampFormat>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<...>
</project>
Explanation:
<profiles>
<profile>
<id>buildnumber</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
--- Plugin definition and configuration here ---
</plugin>
</plugins>
</build>
</profile>
</profiles>
The important part is the <activation> tag you can see that this tag is followed by the <activateByDefault>true</activateByDefault> tag, which indicates, that this profile will be executed everytime without name it explicitly with the maven call.
Within the <build> tag you can specify the plugins including its configuration (when adding a plugin to this section ensure that it will be only defined in this section and not within the standard <plugins> tag again).
2. By default these profile will be executed when you run a maven goal on the project, for example:
mvn test
But in my case I want to execute this profile NOT when running Maven with the goal test, so my modified command now looks like:
mvn test -P!buildnumber
Explanation:
The parameter -P<profileId> says Maven to execute the specified profile by executing the maven command.
To ignore a specific profile you can call maven with the Parameter -P!<profileName>.
To ignore a specific profile you can call maven with the Parameter -P!<profileName>.
! = negation
* using "CopyArtifactPluing" in Jenkins