title: 'scp' is not recognized as an internal or external command while executing Jenkins file
body: <p>I have a very basic <code>Jenkins pipeline</code> that builds a <code>Java</code> project and deploys the artifact to an <code>EC2</code> instance.</p>
  
  <p>The build part is working fine but the deployment is not working and giving an error related to <code>scp</code>.</p>
  
  <p>I copy pasted the entire <code>scp</code> command present in my <code>Jenkinsfile</code> onto the <code>Windows</code> command prompt to see if that works and copies over the jar to <code>ec2</code> instance successfully, and it did work. </p>
  
  <p><a href="https://i.stack.imgur.com/Puc5K.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Puc5K.png" alt="enter image description here"></a></p>
  
  <p>Not sure why it is not working through <code>Jenkins</code>.</p>
  
  <p><strong>Jenkinsfile</strong></p>
  
  <pre><code>pipeline {
          agent any
          tools {
              maven "Maven3"
          }
          stages {
              stage('Build and Deploy') {
                  steps {
                      script {
                          def os = System.properties['os.name'].toLowerCase()
                          echo "OS: ${os}"                
                          if (os.contains("linux")) {
                            sh "mvn clean install -DskipTests" 
                          } else {
                            bat "mvn clean install -DskipTests"
                            bat "scp -i C:\\Users\\Nital\\.ssh\\LightsailDefaultKey-us-east-1.pem target\\helloworld-rest-app.jar ec2-user@35.175.125.176:/home/ec2-user/app-deploys"
                          }
                      }
                  }
                  post {
                      success {
                          echo 'Build and Deploy - SUCCESS'
                      }
                  } 
              }
          }
      }
  </code></pre>
  
  <p><strong>Windows Command Prompt:</strong></p>
  
  <pre><code>C:\Users\Nital&gt;scp
  usage: scp [-346BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file]
             [-l limit] [-o ssh_option] [-P port] [-S program] source ... target
  </code></pre>
  
  <p><strong>Jenkins Error Log:</strong></p>
  
  <pre><code>[INFO] Installing C:\Program Files (x86)\Jenkins\workspace\helloworld-rest-app-build\pom.xml to C:\Windows\system32\config\systemprofile\.m2\repository\com\example\helloworld-rest-app\0.0.1-SNAPSHOT\helloworld-rest-app-0.0.1-SNAPSHOT.pom
  [INFO] ------------------------------------------------------------------------
  [INFO] BUILD SUCCESS
  [INFO] ------------------------------------------------------------------------
  [INFO] Total time:  3.991 s
  [INFO] Finished at: 2019-01-25T00:11:10-05:00
  [INFO] ------------------------------------------------------------------------
  [Pipeline] bat
  
  C:\Program Files (x86)\Jenkins\workspace\helloworld-rest-app-build&gt;scp -i C:\Users\Nital\.ssh\LightsailDefaultKey-us-east-1.pem target\hellworld-rest-app.jar ec2-user@35.175.125.176:/home/ec2-user/app-deploys 
  'scp' is not recognized as an internal or external command,
  operable program or batch file.
  [Pipeline] }
  [Pipeline] // script
  [Pipeline] }
  [Pipeline] // withEnv
  [Pipeline] }
  [Pipeline] // stage
  [Pipeline] }
  [Pipeline] // withEnv
  [Pipeline] }
  [Pipeline] // withEnv
  [Pipeline] }
  [Pipeline] // node
  [Pipeline] End of Pipeline
  ERROR: script returned exit code 1
  Finished: FAILURE
  </code></pre>