I want to register the command output as a global variable in Jenkins. If I execute my set of commands as below it works well.
sh '''
echo "server xyz.abc.com
123.abc.com
exit
" | nslookup
'''
I am aware of the format by which we register a output to some custom value
script {
tmp_params = sh (script: '<command>', returnStdout: true).trim()
env.custom_var = tmp_param
echo ${env.custom_var
}
However, in my case i want to combine these two together. I tried this way, but it isn’t working
script {
tmp_params = sh (script: 'echo "server xyz.abc.com \n 123.abc.com \n exit \n " | nslookup', returnStdout: true).trim()
env.custom_var = tmp_param
echo ${env.custom_var}
}
It just echoes the value instead of giving a result.
How can I add multiple sets of lines together inside the script block and then assign that as an environmental variable?