title: How to print a Jenkins environment variable inside a sh bash script block
body: <p>I'm trying to write a Jenkins pipeline file which uses groovy and bash script and I would like to print/use some Jenkins environment variables inside a bash script block.</p>
  <p>I want use the sh script block with triple single quotas(to prevent the need to escape all dollar signs etc.):</p>
  <pre><code>sh '''
      code
  '''
  </code></pre>
  <p>Instead of triple double quotas(in this script block jenkins env variables can be used with enough escapes):</p>
  <pre><code>sh &quot;&quot;&quot;
      code
  &quot;&quot;&quot;
  </code></pre>
  <p>My attempts to print $WORKSPACE inside triple double quota block:</p>
  <pre><code>script {
          sh '''
          #!/bin/bash
          echo 1 ${WORKSPACE}
          echo 2 '${WORKSPACE}'
          echo 3 ${workspace}
          echo 4 '${workspace}'
          echo 5.1 $WORKSPACE
          echo 5.2 \$WORKSPACE
          echo 5.2.1 \\$WORKSPACE
          echo 5.2.2 \\\$WORKSPACE
          echo 5.2.3 \\\\$WORKSPACE
          echo 5.2.4 \\\&quot;$WORKSPACE\\\&quot;
          echo 5.2.5 \\&quot;$WORKSPACE\\&quot;
          echo 5.2.6 \&quot;$WORKSPACE\&quot;
          echo 5.2.6 &quot;$WORKSPACE&quot;
          echo 5.3 '\$WORKSPACE'
          echo 5.3.1 \'$WORKSPACE\'
          echo 5.3.2 \'${WORKSPACE}\'
          echo 5.4 &quot;&quot;&quot;$WORKSPACE&quot;&quot;&quot;
          echo 5.5 &quot;$WORKSPACE&quot;
          echo 5.5.1 \&quot;$WORKSPACE\&quot;
          echo 5.5.2 &quot;\&quot;${WORKSPACE}\&quot;&quot;
          echo 5.5.3 \\&quot;${WORKSPACE}\\&quot;
          echo 5.5.4 \\\&quot;${WORKSPACE}\\\&quot;
          echo 5.5.4 \\\&quot;${WORKSPACE}\\\&quot;
          echo 5.6 &quot;\$WORKSPACE&quot;
          echo 6 '$WORKSPACE'
          echo 7 $env.WORKSPACE
          echo 8 '$env.WORKSPACE'
          echo '$workspace'
          '''
      }
  </code></pre>
  <p>Output:</p>
  <pre><code>14:31:52  1
  14:31:52  2 ${WORKSPACE}
  14:31:52  3
  14:31:52  4 ${workspace}
  14:31:52  5.1
  14:31:52  5.2
  14:31:52  5.2.1 $WORKSPACE
  14:31:52  5.2.2 $WORKSPACE
  14:31:52  5.2.3 \
  14:31:52  5.2.4 &quot;&quot;
  14:31:52  5.2.5 &quot;&quot;
  14:31:52  5.2.6 
  14:31:52  5.2.6 
  14:31:52  5.3 $WORKSPACE
  14:31:52  5.3.1 $WORKSPACE
  14:31:52  5.3.2 ${WORKSPACE}
  14:31:52  5.4 
  14:31:52  5.5 
  14:31:52  5.5.1 
  14:31:52  5.5.2 
  14:31:52  5.5.3 &quot;&quot;
  14:31:52  5.5.4 &quot;&quot;
  14:31:52  5.5.4 &quot;&quot;
  14:31:52  5.6 
  14:31:52  6 $WORKSPACE
  14:31:52  7 .WORKSPACE
  14:31:52  8 $env.WORKSPACE
  14:31:52  $workspace
  </code></pre>
  <p>Expected output for at least some of these:</p>
  <pre><code>/home/my_user/jenkins_workspace/workspace/Jenkins_debug_job
  </code></pre>