[workflow-plugin] Error "script.sh: command not found" when running shell script

4,645 views
Skip to first unread message

Rupali

unread,
Nov 28, 2014, 4:39:05 AM11/28/14
to jenkins...@googlegroups.com
Hi,

I tried a simple command in shell script as below:
sh 'echo Hello'

It gives below error:

[D:\Jenkins-Slave\workspace\Setup-WF] Running shell script
cygwin warning:
  MS-DOS style path detected: D:\Jenkins-Slave\workspace\Setup-WF\.fb8e6a28\pid
  Preferred POSIX equivalent is: /cygdrive/d/Jenkins-Slave/workspace/Setup-WF/.fb8e6a28/pid
  CYGWIN environment variable option "nodosfilewarning" turns off this warning.
  Consult the user's guide for more details about POSIX paths:
    http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
sh: D:\Jenkins-Slave\workspace\Setup-WF\.fb8e6a28\script.sh: command not found

Can you please advise what could be wrong here?

Regards,
Rupali

niraj nandane

unread,
Dec 1, 2014, 6:22:59 AM12/1/14
to jenkins...@googlegroups.com
Hi,
Install cygpath plugin and write
#/bin/bash before echo Hello statement

Rupali

unread,
Dec 1, 2014, 7:08:50 AM12/1/14
to jenkins...@googlegroups.com
HI Ninad,

Thank for the reply. But it doesn't work.
Thing is, shell execution works well as part of normal Jenkins job, as a build step.
But it fails to work when I add it as workflow step.
Not sure if workflow plugin has a different way to invoke shell scripts than traditional Jenkins shell script execution.

Regards,
Rupali


On Friday, November 28, 2014 3:09:05 PM UTC+5:30, Rupali wrote:

Rupali

unread,
Dec 2, 2014, 7:55:57 AM12/2/14
to jenkins...@googlegroups.com
Hi,

I tried number of options but this is not working.
Does Shell script in workflow steps works only on Linux/Unix slaves?

Regards,
Rupali

Rupali

unread,
Dec 2, 2014, 10:50:43 AM12/2/14
to jenkins...@googlegroups.com
To debug further, I modified BourneShellScript.java file in DurableTask plugin to print the environment variables with which it is calling the script.
I found that environment variables do not contain path to Cygwin as observed in the output.

Can this be reason for the error I am seeing?
If yes, how to fix that? I have path to Cygwin setup on master and slave nodes thorugh which initial execution gets triggered.

Any inputs on this will be highly appreciated.

Regards,
Rupali

niraj nandane

unread,
Dec 4, 2014, 11:48:35 AM12/4/14
to jenkins...@googlegroups.com

See to work all you need to provide bash path in global settings of jenkins as /bin/bash ..try out this...

--
You received this message because you are subscribed to a topic in the Google Groups "Jenkins Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-users/g0s4kSGQn2I/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/08c6d591-fb2c-4303-8474-bbdef892d3a0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Les Mikesell

unread,
Dec 4, 2014, 1:11:48 PM12/4/14
to jenkinsci-users
On Thu, Dec 4, 2014 at 10:47 AM, niraj nandane <niraj....@gmail.com> wrote:
> See to work all you need to provide bash path in global settings of jenkins
> as /bin/bash ..try out this...
>

If a jenkins windows slave is started by cygwin sshd, it doesn't seem
to propagate the jenkins variable settings. Is there a way to work
around that?

--
Les Mikesell
lesmi...@gmail.com

Rupali

unread,
Dec 5, 2014, 6:35:33 AM12/5/14
to jenkins...@googlegroups.com
I added a Linux slave today and ran the step to execute shell script on Linux slave.
That worked well.
So I am concluding that Shell script in in workflow step is not working on Windows slave.
Let me know if anyone thinks / knows otherwise.

Regards,
Rupali

Jesse Glick

unread,
Jan 8, 2015, 1:35:42 PM1/8/15
to jenkins...@googlegroups.com
On Friday, December 5, 2014 6:35:33 AM UTC-5, Rupali wrote:
So I am concluding that Shell script in in workflow step is not working on Windows slave.

Or more precisely, that shell scripts run via durable-task-plugin (this also includes the CloudBees Long-Running Build plugin) do not work on at least some Cygwin setups. Not surprising, since no one is testing this that I know of (only use of the ‘bat’ step), so pull requests are welcome. The current assumption is that ‘sh’ is available somewhere in the path, which apparently is not true in your case.

Boris Chavez-Bravo

unread,
May 27, 2015, 11:03:44 AM5/27/15
to jenkins...@googlegroups.com
I am facing the exact same issue.  Has anyone come across a solution for this problem?

Simon Richter

unread,
May 27, 2015, 11:39:34 AM5/27/15
to jenkins...@googlegroups.com
Hi,

On 27.05.2015 17:03, Boris Chavez-Bravo wrote:

> I am facing the exact same issue. Has anyone come across a solution for
> this problem?

This smells like one of those cases where you should have been calling
"./script.sh", as the current directory is not on the search path for
very good reasons.

Simon


signature.asc

Les Mikesell

unread,
May 27, 2015, 1:07:41 PM5/27/15
to jenkinsci-users
I'd go further and say that not much of anything you expect works on
Cygwin setups. The environment variables that jenkins should export
to the slaves don't get set in the cygwin environment.

--
Les Mikesell
lesmi...@gmail.com

Boris Chavez-Bravo

unread,
May 27, 2015, 2:39:17 PM5/27/15
to jenkins...@googlegroups.com
I think I have been able to get around this issue by wrapping the call to the script through a batch call:

withEnv(["PATH=C:\\cygwin\\bin;%PATH%"]) {
bat "C:\\cygwin\\bin\\bash ./my_script.sh ${arg1} ${arg2}"
}

Les Mikesell

unread,
May 28, 2015, 3:29:21 PM5/28/15
to jenkinsci-users
On Wed, May 27, 2015 at 1:39 PM, Boris Chavez-Bravo
<bcha...@squareup.com> wrote:
> I think I have been able to get around this issue by wrapping the call to
> the script through a batch call:
>
> withEnv(["PATH=C:\\cygwin\\bin;%PATH%"]) {
> bat "C:\\cygwin\\bin\\bash ./my_script.sh ${arg1} ${arg2}"
> }
>

I don't mean that cygwin isn't in your path, I mean that if you
configure jenkins to start your slaves via ssh you don't get the
environment settings passed to it that are configured globally or per
node in jenkins on the slaves that are windows with cygwin ssh. Most
of our jobs depend on that to find some tools on a UNC path share so
they fail, where the same node connected some other way would work.

--
Les Mikesell
lesmi...@gmail.com
Reply all
Reply to author
Forward
0 new messages