user9711638
user9711638

Reputation: 231

'Bash on Ubuntu on Windows' doesn't work from Jenkins - jenkins job hangs

We use repo and gerrit tool to manage our git repositories and code reviews.

'repo init' and 'repo sync' work fine on our linux slaves, but we have had major problems on windows slaves:

  1. Shebang instruction is ignored on Windows when given in Jenkins 'Execute shell' box, so if we have multiple shells installed on windows slave (MINGW_32, MINGW_64, CYGWIN64, Ubuntu Bash), it is not possible to force the script to be run inside a specific shell by specifying the shebang instcution - it just doesn't work.

  2. We managed to run 'repo sync' on the windows slave from jenkins on the MINGW64 shell - which comes with Git for windows installation. However, 'repo sync' is super slow here. We have tried almost all command line switches and 'repo sync' still the bottleneck. It takes almost 10 mins to complete 'repo sync' in an existing workspace when only a few new changes are getting pulled in.

  3. We installed 'Bash on Ubuntu on Windows' on a non-jenkins machine and tried 'repo sync' from there and voila!, it complete in a couple of mins.

  4. Now, the trouble is that we are unable to use the 'Bash on Ubuntu on Windows' from Jenkins. If we use the Jenkins 'Execute shell' box, we are unable to figure out how to force it to use the Ubuntu bash shell as shebang instruction is ignored on windows slaves (know issue)

If we use Jenkins 'Execute Windows batch command' box, and run something list this: bash -c ls This works on the local machine, but if run from jenkins on windows slave the job just hangs and we see the spinning gear progress icon, eventually we have to kill the jenkins job.

May be we need to modify some windows environment variable to force jenkins to use this shell. The bash.exe is located inside C:\Windows\System32 which is already the first entry in the PATH variable, so we are not sure how we end up using the Ubuntu bash shell from Jenkins.

Upvotes: 2

Views: 2228

Answers (1)

jpadams
jpadams

Reputation: 191

I believe this happens because the Jenkins agent is not allowed to execute from C:\Windows\System32 on Windows 10 when running in the user context. Oddly enough, the logged-in user does not experience the same restriction from a command prompt.

You can workaround this problem by copying the desired executable (such as bash.exe, curl.exe, etc.) from C:\Windows\System32 to C:\bin and adding that new location to the Path. For Example:

set Path=C:\bin\;%Path%
bash -c ls .

Upvotes: 1

Related Questions