Dixon Almeida Dixon Almeida - 1 month ago 16
Groovy Question

How to access global environment through groovy script in Jenkins Pipeline Plugin

In shell we use following command

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?

Answer Source

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

    def xx = sh(returnStdout:true, script:"""
        echo \${x}

    echo "the shell output = ${xx}"