title: Jenkins git credentials work in stage, not in the next one
body: <p>I have the following pipelines file:</p>
  
  <pre><code>node('git') {
      stage('Set Git Config') {
          sh 'git config --global user.email "jenkins@test.com"'
          sh 'git config --global user.name "jenkins"'
          sh 'git config --global credential.helper cache'
          sh "git config --global credential.helper 'cache --timeout=3600'"
      }
      stage('Set Git Credentials') {
          git credentialsId: 'gitlab1', url: '${GITLAB1_REPO}'
          git credentialsId: 'gitlab2', url: '${GITLAB2_REPO}'
      }
      stage('Synchronize with Gitlab2'){
          sh 'git clone --bare ${GITLAB1_REPO} tfs'
          dir("tfs") {
              //add a remote repository
              sh 'git remote add --mirror=fetch second ${GITLAB2_REPO}'
              // update the local copy from the first repository
              sh 'git fetch origin --tags'
  
              // update the local copy with the second repository
              sh 'git fetch second --tags'
  
              // sync back the second repository
              sh 'git push second --all'
              sh 'git push second --tags'
          }
      }
  }
  </code></pre>
  
  <p>Stage 1 and Stage 2 work perfectly. Stage 3 fails with permission denied.</p>
  
  <p>I find this strange because on Stage 2, I can already see what the last commit was so it indicates that the credentials do work. Why aren't they working on stage 3?</p>
  
  <p>This is the error I am seeing:</p>
  
  <blockquote>
    <p>git clone --bare git@bitbucket.test/test.git tfs Cloning
    into bare repository 'tfs'... Permission denied (publickey). fatal:
    Could not read from remote repository.</p>
  </blockquote>
  
  <p>While in stage 2, I see:</p>
  
  <blockquote>
    <blockquote>
      <p>git config core.sparsecheckout # timeout=10
      git checkout -f 30f1a7d1b77ef64e1cd44eab11a6ef4541c23b43
      git branch -a -v --no-abbrev # timeout=10
      git branch -D master # timeout=10
      git checkout -b master 30f1a7d1b77ef64e1cd44eab11a6ef4541c23b43 Commit message: "test commit"</p>
    </blockquote>
  </blockquote>