Exporting MAVEN_OPTS not working for Freestyle Jenkins Projects

I’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”/&gt;
<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>

 

 

 

3 comments

  1. Someone · November 11, 2011

    JVM Opts:-Xmx512m -XX:MaxPermSize=256m

    Just don’t give the JVM the MAVEN_OPT because MAVEN_OPTS is not a argument known from the JVM…

  2. Anonymous · June 27, 2012

    Alternative:
    export MAVEN_OPTS=”$MAVEN_OPTS -Xmx512m”

    • Nayeli · November 18, 2013

      Hi Jonas,I am glad you like the article.1. The UAT sveerr is automatically updated with the latest version. Using the dashboard, you can deploy a specific version to the UAT environment.2. Yes. This can be used to test a bug in a specific version of the software.3. Its up to you how strict you want to be. For applications that have a lot of UI, I would consider manual UAT tests a critical testing criteria that need to be passed. Automatically testing all parts of a UI can be difficult and error prone. Applications that provide web services on the other hand, do not need manual UAT tests since they should be fully covered in your automated integration tests.If you are running Nexus Professional in your company you can also leverage the Nexus Metadata Plugin as described in this .Using the Metadata Plugin you can enrich each artifact with additional information, like: passed manual UAT testing , 4. The dashboard you see here is are multiple HTML pages that are automatically created/updated after each Job is passed. The HTML pages are generated in the Jenkins userContent folder. Files in this directory will be served under the following URL .Greetings,Marcel

Leave a comment