Dixon Almeida Dixon Almeida - 4 days ago 4
Groovy Question

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

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?

Answer

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}"
}