title: Jenkins pipeline to SSH into an instance and call a function
body: <p>How to create a function <code>def test()</code> which does some steps after <code>ssh</code>ing into an instance</p>
  
  <p>I have something like this:</p>
  
  <pre><code>#!/usr/bin/env groovy
  
  def test() {
      cd $testPath
      mv test*.txt archiveFiles
      sh "someScript.sh"
  }
  
  pipeline { 
  agent java
      parameters {
         string(
              name: 'testPath',
              defaultValue: '/home/ubuntu/testFiles',
              description: 'file directory'
          )
      }
          stages {
          stage(test) {
              steps{
                  script{
                      sh "ssh ubuntu@IP 'test()'"
                  }
              }
  
          }
      }
  }
  </code></pre>
  
  <p>I am trying to <code>ssh</code> into an instance and do the steps in the function <code>test()</code> by calling it
  I am getting an error  like this:
  <code>bash: -c: line 1: syntax error: unexpected end of file
  ERROR: script returned exit code 1</code></p>