title: Value returned from a script does not assigned to a variable declared in jenkins declarative pipeline stage
body: <p>I am working on adding a jenkins Declarative pipeline for automation testing. In the test run stage i want to extract the failed tests from the log. i am using a groovy function for extracting the test result. this function is not a part of the jenkins pipeline. It is another script file. The function works fine and it build a string containing the failure details. Inside a pipeline stage i am calling this function and assinging the returned string to another variable. But when i echo the variable value it prints empty string.</p>
  
  <pre><code>pipeline {
      agent {
          kubernetes {
              yamlFile 'kubernetesPod.yml'
          }
      }
      environment{
          failure_msg = ""
      }
      stages {
          stage('Run Test') {
              steps {
                  container('ansible') {
                      script {
                          def notify = load('src/TestResult.groovy')
                          def result = notify.extractTestResult("${WORKSPACE}/testreport.xml")
                          sh "${result}"
                          if (result != "") {
                              failure_msg = failure_msg + result
                          }
                      }
  
                  }  
              }
          }
      post {
          always {
              script {
                  sh 'echo Failure message.............${failure_msg}'
                  }
          }
      }
  }
  </code></pre>
  
  <p>here 'sh 'echo ${result}'' print empty string. But 'extractTestResult()' returns a non-empty string.</p>
  
  <p>Also i am not able to use the environment variable 'failure_msg' in post section it return an error <strong>'groovy.lang.MissingPropertyException: No such property: failure_msg for class: groovy.lang.Binding'</strong></p>
  
  <p>can anyone please help me with this ?</p>
  
  <p>EDIT: </p>
  
  <blockquote>
    <p>Even after i fixed the string interpolation, i was getting the same
    error. That was because jenkins does not allow using 'sh' inside
    docker container. there is an open bug ticket in <a href="https://issues.jenkins-ci.org/browse/JENKINS-58657" rel="nofollow noreferrer">jenkins issue
    board</a></p>
  </blockquote>