How to execute sh file from jenkins running on windows

13,045

Solution 1

here is the solution: Shell executable path to cygwin_home\bin\sh and in jenkins build step->execute shell command give the file name ex *.sh or clear Shell executable path and in jenkins build step->execute windows batch command sh path*.sh

Solution 2

For each windows slave you can do the following to add cygwin to path assuming that your slave has cygwin installed already

  • Jenkins - Manage Jenkins - Manage Nodes
  • node - Configure
  • Environment variables : list of key-value pairs
  • add: name: PATH value: ${PATH};path-to-cygwin\bin

E.g., name: PATH value: ${PATH};d:\tools\cygwin\bin

Share:
13,045
sampath
Author by

sampath

Updated on June 04, 2022

Comments

  • sampath
    sampath almost 2 years

    Cygwin installed in my windows and able to execute the sh file using cmd prompt. same Cygwin plugin has been installed in jenkins which also running in windows. I created a job in jenkins build step->execute shell command I am giving the command as sh /cygdrive/d/539707/data/getchanges/gymBuild.sh while executing the job I am facing below exception.

    NOTE 1: In Jenkins/configuration/ under shell I didn't mention any path

    workspace] $ sh -xe D:\539707\tomcat-7.0.12\temp\hudson4624102689815543789.sh FATAL: command execution failed java.io.IOException: Cannot run program "sh" (in directory "C:\Users\539707.jenkins\jobs\Test_Gym\workspace"): CreateProcess error=2, The system cannot find the file specified at java.lang.ProcessBuilder.start(ProcessBuilder.java:1047) at hudson.Proc$LocalProc.(Proc.java:244) at hudson.Proc$LocalProc.(Proc.java:216) at hudson.Launcher$LocalLauncher.launch(Launcher.java:815) at hudson.plugins.cygpath.CygpathLauncherDecorator$1.launch(CygpathLauncherDecorator.java:66) at hudson.Launcher$ProcStarter.start(Launcher.java:381) at hudson.tasks.CommandInterpreter.perform(CommandInterpreter.java:95) at hudson.tasks.CommandInterpreter.perform(CommandInterpreter.java:64) at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20) at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:782) at hudson.model.Build$BuildExecution.build(Build.java:205) at hudson.model.Build$BuildExecution.doRun(Build.java:162) at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:534) at hudson.model.Run.execute(Run.java:1738) at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43) at hudson.model.ResourceController.execute(ResourceController.java:98) at hudson.model.Executor.run(Executor.java:410) 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.(ProcessImpl.java:385) at java.lang.ProcessImpl.start(ProcessImpl.java:136) at java.lang.ProcessBuilder.start(ProcessBuilder.java:1028) ... 16 more Build step 'Execute shell' marked build as failure

    Finished: FAILURE

    NOTE 2: In Jenkins/configuration/ under shell I mention C:\cygwin\bin\mintty.exe

    After that below is the output

    $ C:\cygwin\bin\cygpath -w C:\cygwin\bin\mintty.exe [workspace] $ C:\cygwin\bin\mintty.exe -xe D:\539707\tomcat-7.0.12\temp\hudson4745164988293910592.sh /usr/bin/mintty: unknown option '-x' Try '--help' for more information. Build step 'Execute shell' marked build as failure

    Finished: FAILURE

    Kindly suggest How to execute sh file from jenkins running on windows

  • Peter Kahn
    Peter Kahn about 8 years
    Nope I'm wrong. One node does this and another fails. The only way that I know to make this work is: modify system env to include cygwin/bin on path, restart box to ensure system user which executes services takes the change