Exporting MAVEN_OPTS not working for Freestyle Jenkins Projects
Join the DZone community and get the full member experience.
Join For Freei’m running jenkins version 1.428 and i have a “freestyle” project. the aim of this project is to upload a large tar.gz file to an artifactory repository. the team are using maven so we started out by looking at using maven to do the deployment. it seems simple enough – you just choose “invoke top-level maven targets” and add the usual maven deploy details here, like so:
the trouble is, because the tar is so large (126mb in this instance), it fails with a java heap space issues (out of memory exception). so, it would be very tempting to try to increase the maven_opts by passing it via the jvm options, as shown below:
sadly, this doesn’t work. it fails with an ugly error saying maven_opts isn’t recognised, or some such thing.
now, in an attempt to be clever, we thought we could simply execute a shell command first, and get that to set the maven_opts, like so:
good ideah huh? yeah, well it didn’t work
it looks like there’s a general issue with setting maven_opts for freestyle projects in jenkins version 1.428 – see here for details.
workarounds:
there’s actually a couple of workarounds. firstly, you can run maven via the shell execution command, and explicitly pass the maven_opts value:
this actually works fine, and is the preferred way of doing it in our case.
the other option is to use ant to do the deployment – this somehow seems to use a lot less memory and doesn’t fail quite so easily. also, you don’t have this issue with the maven_opts being passed as you can set it directly in the ant file. here’s the ant file i created (i also created a very basic pom.xml):
<project name=”artifactory_deploy” basedir=”.” default=”deploy_to_repo” xmlns:artifact=”antlib:org.apache.maven.artifact.ant”>
<description>sample deploy script</description>
<taskdef resource=”net/sf/antcontrib/antcontrib.properties”/><property name=”to.name” value=”myrepo” />
<property name=”artifactory.url” value=”http://artifactory.mycompany.com”/>
<property name=”jar.name” value=”massive.tar.gz”/><target name=”deploy_to_repo” description=”deploy build to repo in artifactory” >
<artifact:pom id=”mypom” file=”pom.xml” />
<artifact:deploy file=”${jar.name}”>
<remoterepository url=”${artifactory.url}/${to.name}” />
<pom refid=”mypom” />
</artifact:deploy>
</target></project>
source : http://jamesbetteley.wordpress.com/2011/11/10/exporting-maven_opts-not-working-for-freestyle-jenkins-projects/
Opinions expressed by DZone contributors are their own.
Comments