Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8620121
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:30:30+00:00 2026-06-12T06:30:30+00:00

My project takes in a version number (separated by ‘.’ or ‘_’). I tried

  • 0

My project takes in a version number (separated by ‘.’ or ‘_’). I tried writing a Groovy script that creates a Jenkins environment variable using only the first two of these numbers:

//Get the version parameter
def env = System.getenv()
def version = env['currentversion']
def m = version =~/\d{1,2}/
env = ['miniVersion':m[0].m[1]]

Am I doing this correctly? Can I even create a new environment variable? Is there a better solution to this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T06:30:31+00:00Added an answer on June 12, 2026 at 6:30 am

    Jenkins 1.x

    The following groovy snippet should pass the version (as you’ve already supplied), and store it in the job’s variables as ‘miniVersion’.

    import hudson.model.*
      
    def env = System.getenv()
    def version = env['currentversion']
    def m = version =~/\d{1,2}/
    def minVerVal = m[0]+"."+m[1]
      
    def pa = new ParametersAction([
      new StringParameterValue("miniVersion", minVerVal)
    ])
      
    // add variable to current job
    Thread.currentThread().executable.addAction(pa)
    

    The variable will then be accessible from other build steps. e.g.

    echo miniVersion=%miniVersion%
    

    Outputs:

    miniVersion=12.34
    

    I believe you’ll need to use the "System Groovy Script" (on the Master node only) as opposed to the "Groovy Plugin" – https://wiki.jenkins-ci.org/display/JENKINS/Groovy+plugin#Groovyplugin-GroovyScriptvsSystemGroovyScript

    Jenkins 2.x

    I believe the previous (Jenkins 1.x) behaviour stopped working because of this Security Advisory…

    Solution (paraphrased from the Security Advisory)

    It’s possible to restore the previous behaviour by setting the system property hudson.model.ParametersAction.keepUndefinedParameters to true. This is potentially very unsafe and intended as a short-term workaround only.

    java -Dhudson.model.ParametersAction.keepUndefinedParameters=true -jar jenkins.war
    

    To allow specific, known safe parameter names to be passed to builds, set the system property hudson.model.ParametersAction.safeParameters to a comma-separated list of safe parameter names.

    e.g.

    java -Dhudson.model.ParametersAction.safeParameters=miniVersion,FOO,BAR -jar jenkins.war
    

    And in groovy these two lines should be written this way:

    System.setProperty("hudson.model.ParametersAction.keepUndefinedParameters","true");
    System.setProperty("hudson.model.ParametersAction.safeParameters","miniVersion,FOO,BAR");  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I work on a project that takes 2-3 minuts to compile. Usually when I
I'm working on a web project that takes the results from a survey type
I have a fully working Setup project within Visual Studio 2008 that takes inputs
I have a Maven plugin that takes a groupId, artifactId, and version in its
I am updating an old project that used an old version of cjson to
I have taken over a project that was build from suggestions in this Dan
While writing a post about project euler's 14th problem I ran into a difference
Every time I paste a new dll version of my project and request my
I work on a large Scala project where we use Git for version control.
What I'm trying to do is compile to a file which takes it's version

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.