title: Reading an environment variable set by a test in Jenkins pipeline
body: <p>Not found any reference to this particular question. </p>
  
  <p>I am looking to find a way to achieve something like this in a Jenkins pipeline which runs our acceptance tests using Protractor and Cucumber.js:</p>
  
  <pre><code>            steps {
                  container('selenium') {
                      script {
                          try {
                               {
                                  //run tests
                              }
                          }
                          catch (err) {
                              if (env.testFailed == 'true') {
                                  println "A test failure exists - build status updated to failure"
                                  currentBuild.result = 'FAILURE'
                                  error "Test(s) have failed"
                              } 
                              else {
                                  println "No test failures exist - build status updated to success"
                                  currentBuild.result = 'SUCCESS'
                              }
                          }
                      }
                  }
              }
  </code></pre>
  
  <p>This would fail the build if the env var of testFailed is 'true'. The reason for this is we are encountering bugs with Protractor-Cucumber framework where if a failed test retries and passes the exit code of the stage is still 1. </p>
  
  <p>So in the After hook of each test I am setting the env var using node.js to true if the Scenario status is failed:</p>
  
  <pre><code>  if (scenario.result.status === Status.FAILED) {
      process.env.testFailed = 'true';
    }
    if (scenario.result.status === Status.PASSED) {
      process.env.testFailed = 'false';
    }
  </code></pre>
  
  <p>The problem I have found is that the Jenkins pipeline fails to read the env var value in the code block of the catch section. It is always null.</p>
  
  <p>Any ideas? </p>