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

BourneShellScript fails on Cygwin due to use of slashes vs. backslashes

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Critical Critical
    • durable-task-plugin
    • Latest jenkins on linux, Windows agent via jnlp slave agent

      This is related but not the same as JENKINS-33708 .

      I'm trying to run pipeline code on windows via cygwin bash:

      stage("test") {
          node("windows"){
              sh """#!/bin/bash
              echo hello world"""
          }
      }
      

      The output of the workflow looks like that:

      [c:\b\workspace\test_wintendo_pipeline] Running shell script
      sh: c:\b\workspace\test_wintendo_pipeline@tmp\durable-4da51fcf\script.sh: command not found
      

      After some fiddling with procmon I insulated what it was actually doing:

      nohup sh -c "echo $$ > 'c:\b\workspace\test_wintendo_pipeline@tmp\durable-4da51fcf\pid'; jsc=durable-6eaaad0f799f776c331f1724d18dab7f; JENKINS_SERVER_COOKIE=$jsc 'c:\b\workspace\test_wintendo_pipeline@tmp\durable-4da51fcf\script.sh' > 'c:\b\workspace\test_wintendo_pipeline@tmp\durable-4da51fcf\jenkins-log.txt' 2>&1; echo $? > 'c:\b\workspace\test_wintendo_pipeline@tmp\durable-4da51fcf\jenkins-result.txt'"
      

      Reducing it to what actually causes the error that we see in the scripts output in jenkins:

      sh -c "'c:\b\workspace\durable-bc34ce35\script.sh'"
      sh: c:\b\workspace\durable-bc34ce35\script.sh: command not found
      

      Fixing it seems only be possible by using slashes instead of backslashes:

      sh -c "'c:/b/workspace/durable-bc34ce35/script.sh'"
      + echo hello world
      hello world
      

          [JENKINS-40225] BourneShellScript fails on Cygwin due to use of slashes vs. backslashes

          Wilfried Goesgens created issue -
          Jesse Glick made changes -
          Description Original: This is related but not the same as JENKINS-33708 .

          I'm trying to run pipeline code on windows via cygwin bash:

          {code:code}
          stage("test") {
              node("windows"){
                  sh """#!/bin/bash
                  echo hello world"""
              }
          }
          {code}

          The output of the workflow looks like that:
          {code:code}
          [c:\b\workspace\test_wintendo_pipeline] Running shell script
          sh: c:\b\workspace\test_wintendo_pipeline@tmp\durable-4da51fcf\script.sh: command not found
          {code}

          After some fiddling with procmon I insulated what it was actually doing:

          {code:code}
          nohup sh -c "echo $$ > 'c:\b\workspace\test_wintendo_pipeline@tmp\durable-4da51fcf\pid'; jsc=durable-6eaaad0f799f776c331f1724d18dab7f; JENKINS_SERVER_COOKIE=$jsc 'c:\b\workspace\test_wintendo_pipeline@tmp\durable-4da51fcf\script.sh' > 'c:\b\workspace\test_wintendo_pipeline@tmp\durable-4da51fcf\jenkins-log.txt' 2>&1; echo $? > 'c:\b\workspace\test_wintendo_pipeline@tmp\durable-4da51fcf\jenkins-result.txt'"
          {code}

          Reducing it to what actually causes the error that we see in the scripts output in jenkins:
          {code:code}
          sh -c "'c:\b\workspace\durable-bc34ce35\script.sh'"
          sh: c:\b\workspace\durable-bc34ce35\script.sh: command not found
          {code}

          Fixing it seems only be possible by using slashes instead of backslashes:

          {code:code}
          sh -c "'c:/b/workspace/durable-bc34ce35/script.sh'"
          + echo hello world
          hello world
          {code}

          New: This is related but not the same as JENKINS-33708 .

          I'm trying to run pipeline code on windows via cygwin bash:

          {code}
          stage("test") {
              node("windows"){
                  sh """#!/bin/bash
                  echo hello world"""
              }
          }
          {code}

          The output of the workflow looks like that:
          {code:none}
          [c:\b\workspace\test_wintendo_pipeline] Running shell script
          sh: c:\b\workspace\test_wintendo_pipeline@tmp\durable-4da51fcf\script.sh: command not found
          {code}

          After some fiddling with procmon I insulated what it was actually doing:

          {code:none}
          nohup sh -c "echo $$ > 'c:\b\workspace\test_wintendo_pipeline@tmp\durable-4da51fcf\pid'; jsc=durable-6eaaad0f799f776c331f1724d18dab7f; JENKINS_SERVER_COOKIE=$jsc 'c:\b\workspace\test_wintendo_pipeline@tmp\durable-4da51fcf\script.sh' > 'c:\b\workspace\test_wintendo_pipeline@tmp\durable-4da51fcf\jenkins-log.txt' 2>&1; echo $? > 'c:\b\workspace\test_wintendo_pipeline@tmp\durable-4da51fcf\jenkins-result.txt'"
          {code}

          Reducing it to what actually causes the error that we see in the scripts output in jenkins:
          {code:none}
          sh -c "'c:\b\workspace\durable-bc34ce35\script.sh'"
          sh: c:\b\workspace\durable-bc34ce35\script.sh: command not found
          {code}

          Fixing it seems only be possible by using slashes instead of backslashes:

          {code:none}
          sh -c "'c:/b/workspace/durable-bc34ce35/script.sh'"
          + echo hello world
          hello world
          {code}

          Jesse Glick made changes -
          Labels New: windows
          Jesse Glick made changes -
          Link New: This issue relates to JENKINS-33708 [ JENKINS-33708 ]
          Jesse Glick made changes -
          Summary Original: Invocation of 'sh' pipeline step fails on windows New: Invocation of 'sh' pipeline step fails on Windows due to use of slashes vs. backslashes
          Jesse Glick made changes -
          Summary Original: Invocation of 'sh' pipeline step fails on Windows due to use of slashes vs. backslashes New: BourneShellScript fails on Cygwin due to use of slashes vs. backslashes

          Java source involved in this bug:
          https://github.com/jenkinsci/durable-task-plugin/src/main/java/org/jenkinsci/plugins/durabletask/BourneShellScript.java
          https://github.com/jenkinsci/pipeline-plugin/tree/1.14.x / durable-task-step/src/main/java/org/jenkinsci/plugins/workflow/steps/durable_task/ShellStep.java
          https://github.com/jenkinsci/pipeline-plugin/tree/1.14.x / durable-task-step/src/main/java/org/jenkinsci/plugins/workflow/steps/durable_task/DurableTaskStep.java

          Wilfried Goesgens added a comment - Java source involved in this bug: https://github.com/jenkinsci/durable-task-plugin/src/main/java/org/jenkinsci/plugins/durabletask/BourneShellScript.java https://github.com/jenkinsci/pipeline-plugin/tree/1.14.x / durable-task-step/src/main/java/org/jenkinsci/plugins/workflow/steps/durable_task/ShellStep.java https://github.com/jenkinsci/pipeline-plugin/tree/1.14.x / durable-task-step/src/main/java/org/jenkinsci/plugins/workflow/steps/durable_task/DurableTaskStep.java

          Bertrand Latinville added a comment - - edited

          I'm evaluating the pipeline plugin to migrate existing jobs, and I also faced this issue using the cygwin ssh server to connect to the node.
          We are running the same shell scripts on multiple plaftorm (windows, linux, mac ), and this issue is blocking for us.

          From Wilfried's comment regarding java source, I made a commit to replace backslashes.

          https://github.com/blatinville/durable-task-plugin/commit/362f8959cd4c289e1614d6aeecf503863da70903

          Shell script on windows are working,tested with

          • cygwin, node connected with ssh server
          • git bash using, node connected with JNLP

          Bertrand Latinville added a comment - - edited I'm evaluating the pipeline plugin to migrate existing jobs, and I also faced this issue using the cygwin ssh server to connect to the node. We are running the same shell scripts on multiple plaftorm (windows, linux, mac ), and this issue is blocking for us. From Wilfried's comment regarding java source, I made a commit to replace backslashes. https://github.com/blatinville/durable-task-plugin/commit/362f8959cd4c289e1614d6aeecf503863da70903 Shell script on windows are working,tested with cygwin, node connected with ssh server git bash using, node connected with JNLP
          Jesse Glick made changes -
          Remote Link New: This issue links to "PR 33 (Web Link)" [ 15195 ]
          Jesse Glick made changes -
          Assignee New: Bertrand Latinville [ blatinville ]

            blatinville Bertrand Latinville
            dothebart Wilfried Goesgens
            Votes:
            2 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: