Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-47787

Multiline shell script should take interpreter from first non-blank line

      When using a mutli-line quote, the interpreter must be on the first line, which doesn't look as nice.

      Works:

      sh """#!/bin/bash -xel
        set -o pipefail
        # Do stuff.
        """
      

      Want:

      sh """
        #!/bin/bash -xel
        set -o pipefail
        # Do stuff.
        """
      

      (The latter will be passed to the default shell and ignored as a comment since it is on the second line.)

          [JENKINS-47787] Multiline shell script should take interpreter from first non-blank line

          A workaround of putting .trim() at the end of the triple-double quote does work:

          sh """
            #!/bin/bash -xel
            set -o pipefail
            # do stuff
            """.trim()
          

          Aaron D. Marasco added a comment - A workaround of putting .trim() at the end of the triple-double quote does work: sh """ #!/bin/bash -xel set -o pipefail # do stuff """.trim()

          Jesse Glick added a comment -

          Erring on the side of using the supplied input exactly rather than trying to guess what was meant.

          Jesse Glick added a comment - Erring on the side of using the supplied input exactly rather than trying to guess what was meant.

            Unassigned Unassigned
            aarondmarasco_vsi Aaron D. Marasco
            Votes:
            2 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: