How catch curl response into variable in Jenkinsfile : <p>I want to curl an URL and capture the response into a variable.</p>

<p>when I curl a command and echo its output I get the correct response as below</p>

<pre><code>sh 'output=`curl https://some-host/some-service/getApi?apikey=someKey`;echo $output;'
</code></pre>

<p>I want to catch the same response into a variable and use that response for further operation</p>

<p>Below is my Jenkinsfile</p>

<pre><code>pipeline {
    agent {
          label "build_2"
       }
    stages {
        stage('Build') {
            steps {
                checkout scm
                sh 'npm install'

            }
        }
        stage('Build-Image') {
            steps {
                echo '..........................Building Image..........................'

                //In below line I am getting Output
                //sh 'output=`curl https://some-host/some-service/getApi?apikey=someKey`;echo $output;'

                script {
                    //I want to get the same response here
                    def response = sh 'curl https://some-host/some-service/getApi?apikey=someKey'
                    echo '=========================Response===================' + response
                }
            }
        }
    }
}
</code></pre>

<p>Can you please tell me what changes I need to do in my Jenkinsfile</p>
