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

Invocation of 'sh' on Windows should provide a more helpful error

    XMLWordPrintable

Details

    Description

      Right now if your pipeline script inadvertently tries to invoke the sh step, something approximating this error will fail your build:

      java.io.IOException: Cannot run program "nohup" (in directory "C:\Program Files (x86)\Jenkins\workspace\fathertime"): CreateProcess error=2, The system cannot find the file specified
      	at java.lang.ProcessBuilder.start(Unknown Source)
      	at hudson.Proc$LocalProc.<init>(Proc.java:244)
      	at hudson.Proc$LocalProc.<init>(Proc.java:216)
      	at hudson.Launcher$LocalLauncher.launch(Launcher.java:815)
      	at hudson.Launcher$ProcStarter.start(Launcher.java:381)
      	at org.jenkinsci.plugins.durabletask.BourneShellScript.launchWithCookie(BourneShellScript.java:130)
      	at org.jenkinsci.plugins.durabletask.FileMonitoringTask.launch(FileMonitoringTask.java:59)
      	at org.jenkinsci.plugins.workflow.steps.durable_task.DurableTaskStep$Execution.start(DurableTaskStep.java:98)
      	at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:136)
      	at org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.java:113)
      	at groovy.lang.MetaClassImpl.invokeMethodOnGroovyObject(MetaClassImpl.java:1277)
      	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1171)
      	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1021)
      	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:812)
      	at groovy.lang.GroovyObjectSupport.invokeMethod(GroovyObjectSupport.java:46)
      	at groovy.lang.MetaClassImpl.invokeMethodOnGroovyObject(MetaClassImpl.java:1277)
      	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1171)
      	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1021)
      	at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:42)
      	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
      	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
      	at com.cloudbees.groovy.cps.sandbox.DefaultInvoker.methodCall(DefaultInvoker.java:15)
      	at WorkflowScript.run(WorkflowScript:11)
      	at ___cps.transform___(Native Method)
      	at com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:55)
      	at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:106)
      	at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixArg(FunctionCallBlock.java:79)
      	at sun.reflect.GeneratedMethodAccessor174.invoke(Unknown Source)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      	at java.lang.reflect.Method.invoke(Unknown Source)
      	at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
      	at com.cloudbees.groovy.cps.impl.ConstantBlock.eval(ConstantBlock.java:21)
      	at com.cloudbees.groovy.cps.Next.step(Next.java:58)
      	at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:154)
      	at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:164)
      	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:277)
      	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$000(CpsThreadGroup.java:77)
      	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:186)
      	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:184)
      	at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:47)
      	at java.util.concurrent.FutureTask.run(Unknown Source)
      	at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:112)
      	at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
      	at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
      	at java.util.concurrent.FutureTask.run(Unknown Source)
      	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
      	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
      	at java.lang.Thread.run(Unknown Source)
      Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
      	at java.lang.ProcessImpl.create(Native Method)
      	at java.lang.ProcessImpl.<init>(Unknown Source)
      	at java.lang.ProcessImpl.start(Unknown Source)
      	at java.lang.ProcessBuilder.start(Unknown Source)
      	at hudson.Proc$LocalProc.<init>(Proc.java:244)
      	at hudson.Proc$LocalProc.<init>(Proc.java:216)
      	at hudson.Launcher$LocalLauncher.launch(Launcher.java:815)
      	at hudson.Launcher$ProcStarter.start(Launcher.java:381)
      	at org.jenkinsci.plugins.durabletask.BourneShellScript.launchWithCookie(BourneShellScript.java:130)
      	at org.jenkinsci.plugins.durabletask.FileMonitoringTask.launch(FileMonitoringTask.java:59)
      	at org.jenkinsci.plugins.workflow.steps.durable_task.DurableTaskStep$Execution.start(DurableTaskStep.java:98)
      	at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:136)
      	at org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.java:113)
      	at groovy.lang.MetaClassImpl.invokeMethodOnGroovyObject(MetaClassImpl.java:1277)
      	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1171)
      	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1021)
      	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:812)
      	at groovy.lang.GroovyObjectSupport.invokeMethod(GroovyObjectSupport.java:46)
      	at groovy.lang.MetaClassImpl.invokeMethodOnGroovyObject(MetaClassImpl.java:1277)
      	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1171)
      	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1021)
      	at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:42)
      	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
      	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
      	at com.cloudbees.groovy.cps.sandbox.DefaultInvoker.methodCall(DefaultInvoker.java:15)
      	... 24 more
      Finished: FAILURE
      

      I expect the build to error out, but something more helpful would be nice, like "The `sh` step is not supported on the Windows platform, please use `bat` or install Cygwin"

      Attachments

        Issue Links

          Activity

            ethorsa ethorsa added a comment - - edited

            I had to set the PATH System variable on the computer before I could get sh to work on Windows.

            That's important, it doesn't work otherwise. Adding it to PATH from within the pipeline (eg. withEnv(...) or environment { ... }) doesn't work.

            ethorsa ethorsa added a comment - - edited I had to set the PATH System variable on the computer before I could get  sh  to work on Windows. That's important, it doesn't work otherwise. Adding it to PATH from within the pipeline (eg. withEnv(...)  or environment { ... }) doesn't work.
            pausaca pau sabats added a comment -

            The error related with : 
            Cannot run program "nohup"
            means that it's searching for nohup.exe because is what jenkins requires when using 'sh' in the pipeline, so you can use nuhup.exe from here: "C:\Program Files\Git\usr\bin".

            Eventhough, what I have done in order to solve this issue is the following: Create a if else statement in your jenkinsfile that does:

                 if (isUnix()) --> sh "command"

                 else --> bat "command"

            doing so the pipeline running on agent windows will run as bat and this error no longer appears.

            Note: You can also use "tool config configuration" of jenkins and install tools from there. In case your sh commands were related with installation files

             

             

             

            pausaca pau sabats added a comment - The error related with :  Cannot run program "nohup" means that it's searching for nohup.exe because is what jenkins requires when using 'sh' in the pipeline, so you can use nuhup.exe from here: "C:\Program Files\Git\usr\bin". Eventhough, what I have done in order to solve this issue is the following: Create a if else statement in your jenkinsfile that does:      if (isUnix()) --> sh "command"      else --> bat "command" doing so the pipeline running on agent windows will run as bat and this error no longer appears. Note: You can also use "tool config configuration" of jenkins and install tools from there. In case your sh commands were related with installation files      
            lvshaoxia_123 Lv Shaoxia added a comment -

            As added the git/bin & git/usr/bin to System PATH, reconnect the windows node is needed.

            lvshaoxia_123 Lv Shaoxia added a comment - As added the git/bin & git/usr/bin to System PATH, reconnect the windows node is needed.
            knurd Jule added a comment -

            keeftm We have EXACTLY the same problem.

            We are connecting the worker via SSH with a user that has admin rights. All Git folders are in the PATH, both system and user. I can easily run nohup when I do, cmd.exe -> sh.exe -> nohup --help.

            What can we do???

            knurd Jule added a comment - keeftm We have EXACTLY the same problem. We are connecting the worker via SSH with a user that has admin rights. All Git folders are in the PATH, both system and user. I can easily run nohup when I do, cmd.exe -> sh.exe -> nohup --help. What can we do???
            knurd Jule added a comment -

            The mklink softlinks actually worked. I agree that adding Git/usr/bin to the PATH is NOT an option.

            Why does jenkins not just call "nohup" from inside the shell/batch that was requested?? This is a horrible user experience.

            knurd Jule added a comment - The mklink softlinks actually worked. I agree that adding Git/usr/bin to the PATH is NOT an option. Why does jenkins not just call "nohup" from inside the shell/batch that was requested?? This is a horrible user experience.

            People

              jglick Jesse Glick
              rtyler R. Tyler Croy
              Votes:
              18 Vote for this issue
              Watchers:
              28 Start watching this issue

              Dates

                Created:
                Updated: