How can I let jenkins run `bash` command on windows? - windows

I have setup a jenkins server on windows10 pro and installed ubuntu bash on the system. And I created a Executable windows batch command and put the command bash -c ls there. When executing this job I got below error:
c:\jenkins\workspaces>bash -c ls
'bash' is not recognized as an internal or external command,
operable program or batch file.
It says that bash is not recognized as an internal or external command. Then I tried to use the absolute path but still not work. The error is shown as below:
c:\jenkins\workspaces>C:\Windows\System32\bash.exe -c ls
'C:\Windows\System32\bash.exe' is not recognized as an internal or external command,
operable program or batch file.
I can run the command manually on windows. How can I configure this on jenkins? I need to run the build command from windows normal command window and in my build script it needs to launch a process inside bash.

You could install MsysGit, which includes bash, and in Jenkins you have to set the shell executable, which is the path to the sh.exe
You could also install cygwin, but i think this uses high amount of RAM for just running bash scripts.

similiar to what #Borislav said, a migrated shell might help, if you had mingw or msys2 and start your java -jar slave.jar from that bash console, you should be able to directly chose to execute shell, just considering it to be a linux node at your jenkins

Try to install git. Git hold a minimal bash environment which can help in your case.
https://git-scm.com/

Related

WebStorm mocha test 'sh' is not recognized as an internal or external command

I'm trying to run a mocha test for my node.js code which runs the following line:
exec(`sh ${scriptFile}`);
When I run it from the command line (Git Bash) using npm test, it passes. However, when I run it from WebStorm I get the following error:
'sh' is not recognized as an internal or external command,
operable program or batch file.
I feel like I'm probably missing some WebStorm setting, but I can't figure out what it is. Any ideas?
P.S. I'm on Windows.
For those who are using phpStorm on Windows and come here by Google
Install Git on your machine. Go to Settings/Terminal and set shell path to C:\Program Files\Git\bin\sh.exe
Also add C:\Program Files\Git\bin to your PATH in environment variables.
Git Bash implements a *nix-esque shell simulating bash which can parse your command. Webstorm appears to be trying to execute your command in either powershell or cmd, which do not support sh syntax.
Open the Terminal page of the Settings/Preferences dialog, and configure the Shell path field as follows:
"[path to the git installation]\bin\sh.exe" -login -i
This will probably be "C:\Program Files\Git\bin\sh.exe" -login -i
Source: https://www.jetbrains.com/help/webstorm/2017.1/working-with-embedded-local-terminal.html

bash -c from bat file spawned from exe not a command

When I run a batch file that runs bash -c (part of windows subsystem for linux/Bash on ubuntu on windows) as a child process of an exe (pidgin), even if the exe is elevated/administrator in Windows the batch file errors:
'bash' is not recognized as an internal or external command,
operable program or batch file.
The .bat file that I am running is:
bash -c "curl --silent -u '''my api key'':' -d type='note' -d body='My Message' -d title='My Subject' 'https://api.pushbullet.com/v2/pushes'"
pause #disable after debugging
What I intend to do is have it as a 'buddy pounce' in pidgin so that when I get a message from Nickserv, it will notify me everywhere.
I also tried to execute the command from pidgin directly rather than running as a bash file, but the curl never happens, and I don't get a notification through pushbullet. But if I run the exact same command in CMD or in Run, it will use bash and execute the curl successfully.
I also found this question: Calling Windows subsystem for Linux apps through PowerShell/cmd but I'm not sure if it answers that this cannot be done because you clearly can put a bash command in a bat file.
Have you tried fully specifying the path to the bash shell in your batch file?
If you replace the bash command in your curl.bat file with c:\Windows\System32\bash.exe things may work a little better. Seems like pidgin doesn't have your full path environment variable available to the process it spawns.
Change the path to C:\Windows\sysnative\bash.exe. Pidgin is 32-bit so it aliases C:\Windows\System32 to C:\Windows\SysWOW64 and C:\Windows\sysnative to C:\Windows\System32. It would probably make sense for MS to symlink a bash.exe in SysWOW64 to the real one.

How to run shell script on Teamcity Windows agent?

We used to use Jenkins as our CI tool, I can run shell script in Jenkins windows slave, the steps is:
1.install cygwin on Windows slave
2.add step in Jenkins as shell script
3.add "export PATH=/cygdrive/c/dev/tools/cygwin/bin:$PATH " as the first line
then I can execute any shell script in Jenkins.
Now we need to move to teamcity, and I found above steps not work on teamcity.
when I run a "Command line" and set the first line as "export PATH=/cygdrive/c/dev/tools/cygwin/bin:$PATH", it gives me an error as "'export' is not recognized as an internal or external command".
Is there any way to resolve it? I don't want to re-write our shell script into cmd.
This is quite easy to resolve. The error does not come from Cygwin of course, but from CMD. The export command only makes sense within a Bash script; cmd has no way of knowing what to do with it.
What you need to do is simply specify to CMD that the script should run using Cygwin's command interpreter (bash). So you can either just specify the long path to the bash executable and your script, as in
C:\dev\tools\cygwin\bin\bash D:\myscript.sh
or you can just add the path to the cygwin directory to your machine's PATH variable. You can do this by changing the System Settings and append the path there, or you can do it as part of your script above:
# this is not necessary if you have already changed the System Variable to include the path
set PATH=C:\dev\tools\cygwin\bin;%PATH%
bash D:\myscript.sh
There is a good chance you already have Git installed on the agent with Git Bash. Following is how I run npm commands without changing the PATH variable
"C:\Program Files\Git\bin\bash.exe" -c "cd Source && npm install && npm run build"
With this, you can run the shell/bash commands:-
"C:\Program Files\Git\bin\bash.exe" -c "cd Source && npm install && npm run build"
And from Powershell, if you want to run bash scripts :-
& 'C:\Program Files\Git\bin\bash.exe' .\build.sh

Why can Windows command prompt run this file?

I have a ./configure file that I'm supposed to run by putting it in the command prompt. It works when I run it in the git prompt but when I run it in the Windows command prompt it gives me:
C:\cygwin\home\doxygen\configure> configure
'configure' is not recognized as an internal or external command,
operable program or batch file.
Even though I'm in the correct directory (and running dir shows me that the file is there) it still stays that it cannot find the file. This is the same for all files that don't have an extension on them. Why does this happen and how can I get this to work?
./configure is not a program. It's more of a shell script usually. My analogy may not be good but consider it to be the equivalent of windows batch files (in this case you can say it's a .sh without the extension).
It will only run from a cygwin/unix shell.

Jenkins Shell Script Error

I have Cygwin and its bin path is in the path variable. My .sh file association is set to bash.exe. However, when I try to execute a shell script from a Jenkins build, I get the following error:
The system cannot find the file specified
FATAL: command execution failed
java.io.IOException: Cannot run program "sh"
Other posts have indicated this could be an issue with the .sh file association, but I don't see why that would be the case when I'm able to execute .sh files just fine outside of Jenkins. Can anyone tell me if I'm missing a step here? Thanks in advance.
hmm... running jenkins on windows and using cygwin doesn't sound good. are you sure that the command sh is available in your environment? maybe try sh.exe that might work. otherwise start cygwin with bash.exe and try to set an the alias sh to sh.exe... something like that

Resources