Not able to access groovy variable in shell after upgrading jenkins to 1.X to 2.X

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Not able to access groovy variable in shell after upgrading jenkins to 1.X to 2.X

Mahesh Wabale
Hi All , 


Recently i have upgraded jenkins to 2.87 from 1.611 . 

But i am facing issue with groovy . I am not able to access groovy variables in shell . Its giving empty value. 

Here is example : 

In system groovy script : 

  def project = new XmlSlurper().parse(new File("$workspace/pom.xml"))
   
  def ARTIFACT_VERSION=project.version.toString(); 

  println ARTIFACT_VERSION                                                      ==================> It is returning correct value. 



But if i am pring same variable in shell 

  echo $ARTIFACT_VERSION                                                  ===================> it is not printing anything with jenkins 2.X ( but it is working fine with jenkins 1.X) 


Is there any specific changes require to access groovy  variables in shell ? may be syntax or some plugins upgrade ?  


Thanks ,
Mahesh  
  


--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/89efaaca-fff0-481e-b561-f69d889f06d3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Not able to access groovy variable in shell after upgrading jenkins to 1.X to 2.X

Robert Hales
Not sure exactly how it worked in he 1.x versions, but for pipeline, at least, you usually have to either interpolate the variable into the string of the shell script with double quotes: 

    sh "echo ${ARTIFACT_VERSION}"

Or you have to put the in the env object so they get injected into the shell's environment: 

    env.ARTIFACT_VERSION = ARTIFACT_VERSION
    sh
'echo $ARTIFACT_VERSION'




On Monday, November 13, 2017 at 7:33:59 AM UTC-7, Mahesh Wabale wrote:
Hi All , 


Recently i have upgraded jenkins to 2.87 from 1.611 . 

But i am facing issue with groovy . I am not able to access groovy variables in shell . Its giving empty value. 

Here is example : 

In system groovy script : 

  def project = new XmlSlurper().parse(new File("$workspace/pom.xml"))
   
  def ARTIFACT_VERSION=project.version.toString(); 

  println ARTIFACT_VERSION                                                      ==================> It is returning correct value. 



But if i am pring same variable in shell 

  echo $ARTIFACT_VERSION                                                  ===================> it is not printing anything with jenkins 2.X ( but it is working fine with jenkins 1.X) 


Is there any specific changes require to access groovy  variables in shell ? may be syntax or some plugins upgrade ?  


Thanks ,
Mahesh  
  


--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/5612104a-399f-4247-9f41-bebbadb267a7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Not able to access groovy variable in shell after upgrading jenkins to 1.X to 2.X

Mahesh Wabale
I have tried above , but it is not working  . 

Actual issue is below assignment is not working with system groovy script , it is returning null value. 

def ARTIFACT_VERSION=currentBuild.getEnvironment()['POM_VERSION'];        ====> POM_VERSIOM has values xxxx
def artifactVersionParam = new hudson.model.StringParameterValue("ARTIFACT_VERSION", ARTIFACT_VERSION)
def artifactVersionParamAction = new hudson.model.ParametersAction(artifactVersionParam);
currentBuild.addAction(artifactVersionParamAction);
 
println currentBuild.getEnvironment()['POM_VERSION'];                                         =====> output : xxxx 
println currentBuild.getEnvironment()['ARTIFACT_VERSION'];                                =====> output : null 


Because of this such variables are not accessible in environment variables in shell. It is working as expected in jenkins 1.X version.   

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/eabb18db-1db3-4b2d-a425-d421b52bcd56%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Not able to access groovy variable in shell after upgrading jenkins to 1.X to 2.X

Victor Martinez
Couple of points:
- Did you review what changes have been added between both versions? This is the upgrade guide page: https://jenkins.io/doc/upgrade-guide/
- Maybe, I'm wrong but did you try to set hudson.model.ParametersAction.keepUndefinedParameters as true ? Further details: https://wiki.jenkins.io/display/JENKINS/Features+controlled+by+system+properties . 

Cheers

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/94f1f904-2c5c-4f95-ab32-3557a8baac44%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Not able to access groovy variable in shell after upgrading jenkins to 1.X to 2.X

Daniel Beck
In reply to this post by Mahesh Wabale

> On 13. Nov 2017, at 15:33, Mahesh Wabale <[hidden email]> wrote:
>
> Recently i have upgraded jenkins to 2.87 from 1.611 .
>

Something must be missing here, because this never worked as you describe it.

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/3653BCB9-4648-45B6-8077-1B7FD445250B%40beckweb.net.
For more options, visit https://groups.google.com/d/optout.