Q:

Git push fails in Jenkins pipeline? 

I have a Jenkinsfile with several stages.  It is triggered from a BitBucket server using BitBucket Pull Request Notfier plugin, which supplies some parameters.  The first stage does a clean before checkout, a pre-merge, and checks out to a local branch. 
script {
  def scmVars = checkout changelog: true,
                         poll: true,
                         scm: [$class: 'GitSCM', branches: [[name: '${PULL_REQUEST_FROM_BRANCH}']],
                             browser: [$class: 'Stash', repoUrl: '${PULL_REQUEST_TO_SSH_CLONE_URL}'],
                             doGenerateSubmoduleConfigurations: false,
                             extensions: [
                                 [$class: 'CleanCheckout'],
                                 [$class: 'LocalBranch',localBranch:'${PULL_REQUEST_TO_BRANCH}'],
                                 [$class: 'PreBuildMerge', options: [fastForwardMode: 'FF', mergeRemote: 'origin', mergeStrategy: '< object of type org.jenkinsci.plugins.gitclient. MergeCommand. Strategy >', mergeTarget: '${PULL_REQUEST_TO_BRANCH}']]],
                             submoduleCfg: [],
                             userRemoteConfigs: [[credentialsId: 'eae6ff22-2ea6-4300-adf7-ca1efd2ef7eb', url: '${PULL_REQUEST_TO_SSH_CLONE_URL}']]]
}

Later I have a post step to push the merge if the pipeline succeeds. 
post {
  success {
    script {
      powershell 'git push origin "${PULL_REQUEST_TO_BRANCH}"'
    }
  }
  always {
    script {
      currentBuild.result = currentBuild.result ?: ' SUCCESS'
      notifyBitbucket()

    }
    nunit testResultsPattern: "NUnitResult.xml"
  }
}

However the push always fails with. 
powershell.exe : fatal: The current branch develop has no upstream branch. 

At C:\Jenkins\workspace\Website-Integrate@tmp\durable-64c064d3\powershellWrapper.ps1:5 char:3

+   & powershell -NoProfile -NonInteractive -ExecutionPolicy Bypass -Fi ...

+   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (fatal: The curr...pstream branch.:String) [], RemoteException

    + FullyQualifiedErrorId : NativeCommandError

To push the current branch and set the remote as upstream, use

    git push --set-upstream origin develop

script returned exit code 128

From a powershell in the workspace on the slave I do the following:
PS C:\Jenkins\workspace\Website-Integrate> git remote show origin
* remote origin
  Fetch URL: ssh://bitbucket.teamsinspace.com:7999/dev/sitecore.git
  Push  URL: ssh://bitbucket.teamsinspace.com:7999/dev/sitecore.git
  HEAD branch: develop
  Remote branches:
    Team1-Integration               tracked
    Team2-Integration               tracked
    Team3-Integration               tracked
    develop                         tracked
    feature-NEON-10-setup-toll-gate tracked
    master                          tracked
  Local refs configured for 'git push':
    develop                         pushes to develop                         (fast-forwardable)
    feature-NEON-10-setup-toll-gate pushes to feature-NEON-10-setup-toll-gate (up to date)
PS C:\Jenkins\workspace\Website-Integrate>

I can also push from the powershell:
PS C:\Jenkins\workspace\Website-Integrate> git push origin develop
Total 0 (delta 0), reused 0 (delta 0)
To ssh://bitbucket.teamsinspace.com:7999/dev/sitecore.git
   09e22ba528..316dea6c08  develop -> develop

Why does this always fail in the pipeline? 

A:

We cannot substitute Jenkins variables in single quote strings.  For Reference Please read this.  And in your code, the line
 powershell 'git push origin "${PULL_REQUEST_TO_BRANCH}"'

will not replace the variable ${PULL_REQUEST_TO_BRANCH}.  This is causing the error.  Please make the line as
powershell "git push origin \"${PULL_REQUEST_TO_BRANCH}\""

so that it will work.  Hope this is what you need.