Using multi line commands inside script block while registering output value from a command

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
                     " | 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  \n \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?

Hi there,

“it doesn’t work” is always hard to remote debug. Try to always include these 3 things.

  1. what did you try? (Code samples, command lines, screenshots, videos, etc)
  2. what did happen? (Error messages, description, outputs, stuff)
  3. what did you expect to happen?

Otherwise, it’s hard for us to get into your context and you’ll have to have someone who is exactly knowledgeable come along.