title: replacing file variables by envsubst in jenkins pipeline
body: <p>I want to replace some variables in a file having $variablename, at runtime from jenkins pipeline script. It seems envsubst is the best for my use case. When i execute by command line on linux server its working fine but when i'm executing through jenkins pipeline in sh script, nothing happens.</p>
  
  <p>sonar-scanner.properties:</p>
  
  <p>sonar.projectKey=Project:MavenTest$BRANCHNAME
  sonar.projectName=MavenTest$BRANCHNAME</p>
  
  <p>Example of Command line on linux box:</p>
  
  <blockquote>
    <p>$ export BRANCHNAME=develop</p>
    
    <p>$ envsubst '$BRANCHNAME' 
  </blockquote>
  
  <p>Output:</p>
  
  <blockquote>
    <p>sonar.projectKey=Project:MavenTestdevelop</p>
    
    <p>sonar.projectName=MavenTestdevelop</p>
  </blockquote>
  
  <p>But when i'm executing through jenkins file as a script, nothing is changed in file.</p>
  
  <p>jenkins script:</p>
  
  <pre><code> node {
  
      stage('checkout'){
  
          checkout([$class: 'GitSCM', branches: [[name: ':^(?!origin/master$|origin/develop$).*']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'c0ce73db-3864-4360-9c17-d87caf8a9ea5', url: 'http://172.16.4.158:17990/scm/ctoo/testmaven.git']]])
  
      }
  
      stage('initialize variables'){
          // Configuring BRANCH_NAME variable
          sh 'git name-rev --name-only HEAD &gt; GIT_BRANCH'
          sh label: '', script: 'cut -d \'/\' -f 3 GIT_BRANCH &gt; BRANCH'
          branchname = readFile('BRANCH').trim()
          env.BRANCHNAME = branchname
      }
          stage('build &amp; SonarQube analysis') {
              withSonarQubeEnv('Sonar') {
                  sh "envsubst '$BRANCHNAME' &lt;sonar-scanner.properties"
                }
          }
  }
  </code></pre>
  
  <p>Output:
  [Pipeline] sh (hide)</p>
  
  <ul>
  <li>envsubst repotest</li>
  </ul>
  
  <p>sonar.projectKey=Project:MavenTest$BRANCHNAME</p>
  
  <p>sonar.projectName=MavenTest$BRANCHNAME</p>
  
  <p>Can someone please help me</p>