Jenkins on Windows 10 with Bash - bash

I'm currently setting up a Jenkins server on Windows 10, in the hope of being able to make the build scripts more cross platform I was hoping to take advantage of the bash environment that is available in Windows 10.
I hoped this could be done just by setting the path to the shell in Jenkins to be the bash executable, however I've encountered some problems with trying to get this to work.
Firstly when I set the path to be C:\Windows\System32\bash.exe but Jenkins didn't seem to be able to see this path.
I assumed this was because Jenkins was running as 32-bit and changed the path to be C:\Windows\sysnative\bash.exe but when I try and use this I get the error
[workspace] $ C:\Windows\sysnative\bash.exe -xe C:\Users\Jenkins\AppData\Local\Temp\hudson4346151084156392102.sh
Error: 0x80070005
Build step 'Execute shell' marked build as failure
I think I'm poking around in the dark a bit so I didn't know if anyone had any experience of trying to use the bash shell on Windows 10 within Jenkins?

The error 0x80070005 usually appears during Windows Update or by specific applications, because of the .DLL files permission being denied. Look at your permissions and then try again.

You can run this on Windows in order to execute a bash shell script:
bash -c /mnt/c/Users/$LOGNAME/Downloads/abc.sh
Make sure that the script is executable (chmod +x)
(Only works on Windwos 10 with a linux subsystem installed)

Related

Jenkins not running sh commands on windows

When running a sh-command inside of a jenkins pipeline, the commands themselves are not running.
The shell is part of my PATH-variable, thus the cmd-prompt is running, but the commands are not.
Code inside pipeline:
sh "echo Hello World"
bat "echo Hello World"
Result:
[Pipeline] sh
Microsoft Windows [Version 10.0.18362.657]
(c) 2019 Microsoft Corporation. Alle rechten voorbehouden.
C:\Program Files (x86)\Jenkins\workspace\testCI>
[Pipeline] bat
C:\Program Files (x86)\Jenkins\workspace\testCI>echo Hello World
Hello World
How do I get the sh-commands to run?
I'd rather not rely on bat, as this pipeline (and jenkins-workspace) will be moved to a UNIX-environment in the future
Try installing either git bash or cygwin. Sh and Bash executables come by default with them.
You can use path to that sh file here.
Since it's a Windows 10 agent, I recommend installing a Linux subsystem since you plan on moving to a similar environment in the future. However, this would require you to reinstall Jenkins in that subsystem, but it would behave how it would on any other UNIX system out of the gate without having to configure and manage third-party software that is not guaranteed to work on Windows (with Jenkins) as it does on UNIX systems.
You can install a new Jenkins master on the Linux subsystem while keeping the Windows master intact, and then migrate users over when it is configured the way you want it to be.
Installing WSL
https://learn.microsoft.com/en-us/windows/wsl/install-win10

Windows cannot run .ksh script

I have a java code under eclipse that is calling a .ksh script. The OS is Windows7.
I am a complete noob in shell things and the code (both java and ksh) were not written by me (and I cannot change it).
Anyway, when it tries to launch the script, the common Windows popup appears to let me choose a proper application. Given that, I have installed cygwin, but in cygwin/bin/ there is no ksh.exe at all. Even more, I didn't find any on google.
Is there any other way to launch the ksh under Windows?
Thanks in advance
I finally found a log:
C:\Users\Andrea\Desktop\AppXXX\Scripts\Model\Launchksh[35]: mkdir: not found
C:\Users\Andrea\Desktop\AppXXX\Scripts\Model\Launch.ksh[37]: can't create /rep/log/Launch_model.log: No such file or directory
It doesn't find mkdir, is it not an issue related with cygwin?
You need to install the mksh (MirBSD Korn Shell) package. Re-run setup and select mksh.
Ok, I solved the mistery. In the PATH variable there was no reference to the cygwin/bin folder. I manually add it and now it runs!
Thanks all

Jenkins Mac issue

I'm trying to set up Jenkins for continuous integration.
At the moment, I'm trying to do something very simple but am running into issues and I'm not sure if I'm doing something wrong or what I'm trying to do just isn't possible.
I currently have a file, which shows up on PC as a Windows batch file and on Mac as a Unix executable file. I run it from Mac and it uses xcodebuild and xcrun to make and share archives.
What I want to do for now is just have Jenkins do this for me (I'll add more stuff later) so I add added a build step and typed in the path to the batch file:
users/mcbuild/documents/work/fts/ArchiveFTS.bat
However, when I click build I get this:
Started by user anonymous
Building in workspace /Users/Shared/Jenkins/Home/jobs/FTS Build/workspace
[workspace] $ cmd /c call /var/folders/2n/gysykb914qlgtg2b0flhvh4r00007c/T/hudson6994878138376885970.bat
FATAL: command execution failed
java.io.IOException: Cannot run program "cmd" (in directory "/Users/Shared/Jenkins/Home/jobs/FTS Build/workspace"): error=2, No such file or directory
From searching around, I found a couple of possible solutions:
Had to specify the shell to C\windows\system32\cmd.exe
I'm not sure what this means or how to do this, can someone explain this please?
I'm not sure but doesn't it look like Hudson is trying to execute a .bat script on a Unix system?
Does that mean what I'm trying to do isn't possible and if not, what are my options please?
Some suggestions involve checking which user you're using Hudson as and maybe changing that
I'm not sure what user I am using it as or why it comes up as anonymous
Is there an issue with it being anonymous and if so, how do I change it please?
Thanks in advance for your help. If you need any more information please let me know.
It appears that you added a build step of type "Execute Windows batch command", but you are running this job on a Mac. What you need to do is run your xcode/xcrun file from an "Execute shell" build step. If you still have problems, make sure you can manually run the same file from a command prompt on the Mac (not by clicking on it). If you get an error about "Cannot run program sh", you may need to configure the path to sh. Type "which sh" at a command prompt to find out where sh is located. Click on Manage Jenkins, then Configure System, and enter the path under Shell Executable.

jenkins: windows xp, windows 7 slave cannot execute commands

I have a Arch Linux master that drive 2 arch linux slaves, 1 windows xp slave and 1 windows 7 slave. Linux part is all ok, I managed in some way to start windows slave using automatic execution and slave.jar. I have an external program that need to be executed and it's installed on c:\program files (x86) on windows7 and on c:\programs on windows xp.
I went on path variables and inserted the two path on the two systems, but when I try to run jenkins build it says "command not found"
I tryed to place 2 bat files in c:\ poining to the right place, based on every system, but it says c:\build.bat command not found. I can see the file in the right place...
How do you manage executables placed in different places on different computers?
there's a better way to run the program?
I can change everything about this installation, the only thing I need it to find a way for starting that program.
thank you for your help.
Have you verified that the changes you made to the system path were actually saved? Make sure both of the slaves have been rebooted and then test this via a standard command line window.
If the program you're trying to execute is actually on the path, you could also look at the Envfile Plugin.
After adding new paths to your environment variable PATH you need to restart jenkins slave service in order to allow it to use these new PATHs.
I solved the problem changing the way jenkins start the job on the slave. I used "Execute shell" and some program are executed. I changed "Execute shell" with "Execute windows batch command" and everything works fine.

"Too many environment variables" when trying to launch a cywin shell from Hudson

I'm trying to execute a script on a Windows XP Hudson slave in cygwin. This is the shell command as it is configured in Hudson:
#!C:\cygwin\bin\bash.exe
echo "hello"
It seems like it's having a problem getting cygwin to launch on the windows machine and I'm getting this error:
2 [main] bash 2692 C:\cygwin\bin\bash.exe: *** fatal error - C:\cygwin\bin\bash.exe:
*** internal error reading the windows environment - too many environment variables?
So has anyone else experienced this, and any ideas on how to get the script to run?
I wouldn't be surprised if you hit this old error
there is a big problem in Windows
nevertheless. When using ASCII
functions to access the environment,
as Cygwin does, the environment is
silently cut off at 32K.
from http://cygwin.com/ml/cygwin/2005-09/msg00646.html
You can also look at a workaround for starting emacs from a windows shortcut (same error message that you have). May be you can change your bash call to incorporate the cygwin run command as described in the following post.
http://cygwin.com/ml/cygwin/2006-03/msg00156.html

Resources