Home > Enterprise >  Jenkins cannot recognize sh.exe although added to path
Jenkins cannot recognize sh.exe although added to path

Time:09-10

I am trying to run a pipeline with sh instead of bat on Windows.

I have added the following paths in the global properties:

C:\Program Files\Git\usr\bin
C:\Program Files\Git\bin 

but it still does not work.

When I run the pipeline, I get the following error message:

[pipeline] sh
/usr/bin/sh: C:\Program Files\Git\bin\sh.exe: Command not found
[pipeline] }

Note that the file sh.exe is located in the folder C:\Program Files\Git\bin\

However, if I use a Freestyle project with Execute Shell, it works correctly.

What else can I do to fix the problem?

CodePudding user response:

One thing you can do is to set the path variable when the pipeline is running. So basically you run this batch command within your pipeline:

SET PATH=PATH;"C:\Program Files\Git\bin"

and now, if you were to run sh as a batch command, it should refer to the sh.exe in "C:\Program Files\Git\bin

CodePudding user response:

It turns out that the space in Program Files was the one that was causing problems when trying to run the pipeline. Therefore sh.exe was not found in C:\Program Files\Git\bin\.

So I had to move Git\bin location somewhere else where there are no spaces in the path.

  • Related