0

In shell we use following command

  node{
     sh "x=${env.j_properties_file}"
     sh "y=${env.HOME}"
  }

How do we it in groovy script Or How do we access shell variable x in groovy script?

  • Possible duplicate of [Access to build environment variables from a groovy script in a Jenkins build step ( Windows)](https://stackoverflow.com/questions/21236268/access-to-build-environment-variables-from-a-groovy-script-in-a-jenkins-build-st) – alexK Jun 20 '17 at 14:39
  • Im not exactly clear on what you are asking. Can you clarify a bit more? – ptierno Jun 20 '17 at 15:40

1 Answers1

2

you can't access them directly, but according to the reference you can catch stdout from your sh step:

node{
    def xx = sh(returnStdout:true, script:"""
        x=${env.j_properties_file}
        echo \${x}
    """)

    echo "the shell output = ${xx}"
}
daggett
  • 26,404
  • 3
  • 40
  • 56