title: The most clear and concise way to describe SSH commands in .gitlab-ci.yml
body: <p>Usually I make the following job in my <code>.gitlab-ci.yml</code> to execute commands on a remote server via SSH:</p>
  
  <pre><code># The job
  deploy:
    script:
      # I've omitted the SSH setup here
      - |
        ssh gitlab@example.com "
          # Makes the server print the executed commands to stdout. Otherwise only the command output is printed. Required for monitoring and debug.
          set -x &amp;&amp;
  
          # Executes some commands
          cd /var/www/example &amp;&amp;
          command1 &amp;&amp;
          command2 &amp;&amp;
          command3 &amp;&amp;
          command4 &amp;&amp;
          command5
        "
  </code></pre>
  
  <p>It works correctly, but the YAML code looks too complicated:</p>
  
  <ul>
  <li>The <code>set -x</code> command is more a boilerplate than a useful code. It's not required for ordinary CI commands because GitLab CI prints them automatically.</li>
  <li><code>&amp;&amp;</code> on every line is boilerplate too. They make the execution stop when one of a commands fails. Otherwise the next commands will be executed when one fails (in contrast to ordinary job commands).</li>
  <li>All the SSH commands are a single YAML string therefore editors don't highlight the comments and commands so the code is hard to read.</li>
  </ul>
  
  <p>Is there a more clear and convenient way to execute multiple commands on a remote machine through SSH without the cons described above?</p>
  
  <p>I'd like to not use external deployment tools like Ansible to keep the CD configuration as simple as possible (default POSIX/Linux commands are welcome). I'v also considered running each command in a separate <code>ssh</code> call but I'm afraid it may increase the job execution time because of multiple SSH connection establishments (but I'm not sure):</p>
  
  <pre><code>deploy:
    script:
      - ssh gitlab@example.com "cd /var/www/example"
      - ssh gitlab@example.com "command1"
      - ssh gitlab@example.com "command2"
      # ...
  </code></pre>