Run a command shell in jenkins

前端 未结 6 2123
甜味超标
甜味超标 2020-12-16 10:08

I\'m trying to execute a command shell in Jenkins, I\'m working on Windows 7. In the console output I have this:

Building in workspace C:\\Program Files (x86         


        
6条回答
  •  鱼传尺愫
    2020-12-16 10:48

    I was running a job which ran a shell script in Jenkins on a Windows machine. The job was failing due to the error given below. I was able to fix the error thanks to clues in Andrejz's answer.

    Error :

    Started by user james
    Running as SYSTEM
    Building in workspace C:\Users\jamespc\.jenkins\workspace\myfolder\my-job
    [my-job] $ sh -xe C:\Users\jamespc\AppData\Local\Temp\jenkins933823447809390219.sh
    The system cannot find the file specified
    FATAL: command execution failed
    java.io.IOException: CreateProcess error=2, The system cannot find the file specified
        at java.base/java.lang.ProcessImpl.create(Native Method)
        at java.base/java.lang.ProcessImpl.(ProcessImpl.java:478)
        at java.base/java.lang.ProcessImpl.start(ProcessImpl.java:154)
        at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1107)
    Caused: java.io.IOException: Cannot run program "sh" (in directory "C:\Users\jamespc\.jenkins\workspace\myfolder\my-job"): CreateProcess error=2, The system cannot find the file specified
        at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1128)
        at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1071)
        at hudson.Proc$LocalProc.(Proc.java:250)
        at hudson.Proc$LocalProc.(Proc.java:219)
        at hudson.Launcher$LocalLauncher.launch(Launcher.java:937)
        at hudson.Launcher$ProcStarter.start(Launcher.java:455)
        at hudson.tasks.CommandInterpreter.perform(CommandInterpreter.java:109)
        at hudson.tasks.CommandInterpreter.perform(CommandInterpreter.java:66)
        at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
        at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:741)
        at hudson.model.Build$BuildExecution.build(Build.java:206)
        at hudson.model.Build$BuildExecution.doRun(Build.java:163)
        at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:504)
        at hudson.model.Run.execute(Run.java:1853)
        at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
        at hudson.model.ResourceController.execute(ResourceController.java:97)
        at hudson.model.Executor.run(Executor.java:427)
    Build step 'Execute shell' marked build as failure
    Finished: FAILURE
    

    Solution :

    1 - Install Cygwin and note the directory where it gets installed.

    It was C:\cygwin64 in my case. The sh.exe which is needed to run shell scripts is in the "bin" sub-directory, i.e. C:\cygwin64\bin.

    2 - Tell Jenkins where sh.exe is located.

    Jenkins web console > Manage Jenkins > Configure System > Under shell, set the "Shell executable" = C:\cygwin64\bin\sh.exe > Click apply & also click save.

    That's all I did to make my job pass. I was running Jenkins from a war file and I did not need to restart it to make this work.

提交回复
热议问题