Reficio™ - Reestablish your software!

Getting version of the Maven project in a freestyle Jenkins build

Today, I have had to extract the version of a Maven project that is built as a part of a freestyle Jenkins build. There are some stackoverflow posts describing how to do it, but the implicit prerequisite is that the build is a native Maven build – not a freestyle build. That is not what I wanted.

Below, I enclose a script that I have come up with for a Jenkins freestyle build that contains a Maven project step. You may have to adjust the path to the pom.xml file. It is important that the script is executed as a system Groovy script, otherwise the Jenkins’ jars are not on the classpath.

The script sets an environment variable (MAVEN_VERSION) that may be used later on in the build. Enjoy!


  1. Maurits says:

    You want ‘def param = …’ instead of ‘dev param = …;

  2. Rahul says:

    Thanks, corrected typo that Maurtis mentioned and works like a charm.

  3. Murali Nadadhur says:

    def project = new XmlSlurper().parse(new File(“$workspace/pom.xml”))
    For some reason I keep getting FileNotFoundException when the xml is actually there.

    • Eric says:

      Hi Murali,
      If you’re facing FileNotFOundException, it is probably that your build is runnig on a slave. Unfortunately, *system* Groovy scripts run on master exclusively.
      Hope this helps

  4. Everson Jr says:

    Hi guys!
    I don´t know why I am getting this error:

    ERROR: Build step failed with exception
    groovy.lang.MissingMethodException: No signature of method: is applicable for argument types: (hudson.model.StringParameterValue) values: [(StringParameterValue) MAVEN_VERSION='1.0.0_r3']
    Possible solutions: run(), run(), grep(), dump(), any(), every()
    at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(
    at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(
    at groovy.lang.GroovyShell.evaluate(
    at groovy.lang.GroovyShell.evaluate(
    at hudson.plugins.groovy.SystemGroovy.perform(
    at hudson.tasks.BuildStepMonitor$1.perform(
    at hudson.model.AbstractBuild$AbstractBuildExecution.perform(
    at hudson.model.Build$
    at hudson.model.Build$BuildExecution.doRun(
    at hudson.model.AbstractBuild$
    at hudson.model.Run.execute(
    at hudson.model.ResourceController.execute(


  5. Hellko friends, hߋw is аll,and what you ԝould like to say ɑbout tһis paragraph,
    іn my view itѕ truⅼy amazing fօr me.

  6. Νormally I ɗo noot read post ⲟn blogs, howeνer I wish to sаү that
    tҺis writе-up very pressured mе to check out ɑnd do it!
    Your writing style hɑs beewn surprised me. Thanks,
    vеry nice article.

  7. Neel says:

    What if I want to get the following property from “Execute Groovy Script”

    I am running my job in slave node so I want to execute it with “Execute Groovy Script” not with “Execute System Groovy Script”. How can I do this?

  8. poker99 says:

    Attractive section of content. I just stumbled upon your website and
    in accession capital to assert that I get actually enjoyed account your blog posts.

    Anyway I’ll be subscribing to your feeds and even I achievement you access
    consistently rapidly.

Speak Your Mind