Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to run bash scripts on a windows installed runner #1328

Open
brian-pickens opened this issue Sep 13, 2021 · 15 comments
Open

Unable to run bash scripts on a windows installed runner #1328

brian-pickens opened this issue Sep 13, 2021 · 15 comments
Assignees
Labels
enhancement New feature or request Runner Feature Feature scope to the runner

Comments

@brian-pickens
Copy link

Describe the bug
When trying to run a bash script against a windows runner, all the path separators are missing. Presumably the runner is sending backslashes for windows, but should be sending forward slashes in the case of bash.

https://stackoverflow.com/questions/40396613/forward-slash-vs-backward-slash-for-file-path-in-git-bash/40397237#40397237

To Reproduce
Steps to reproduce the behavior:

  1. Run a bash script against a windows runner

Expected behavior
Can execute the temporary *.sh file sent to the runner

Runner Version and Platform

2.281.1

OS of the machine running the runner? OSX/Windows/Linux/...
Windows

What's not working?

image

Job Log Output

Run terraform init
terraform init
shell: C:\Windows\system32\bash.EXE --noprofile --norc -e -o pipefail {0}
env:
ARM_CLIENT_ID: ***
ARM_CLIENT_SECRET: ***
ARM_SUBSCRIPTION_ID: ***
ARM_TENANT_ID: ***
TERRAFORM_CLI_PATH: C:\runners\win_runner_1\run_temp\988e6fdc-5a58-4292-bb9d-3a9aa0c50f0b
/bin/bash: C:runnerswin_runner_1run_temp0124e743-9c40-4523-bd75-62286f04eb6a.sh: No such file or directory
Error: Process completed with exit code 1.

Runner and Worker's Diagnostic Logs

[2021-09-13 18:29:04Z INFO HostContext] No proxy settings were found based on environmental variables (http_proxy/https_proxy/HTTP_PROXY/HTTPS_PROXY)
[2021-09-13 18:29:04Z INFO HostContext] Well known directory 'Bin': 'C:\runners\win_runner_1\bin'
[2021-09-13 18:29:04Z INFO HostContext] Well known directory 'Root': 'C:\runners\win_runner_1'
[2021-09-13 18:29:04Z INFO HostContext] Well known config file 'Credentials': 'C:\runners\win_runner_1.credentials'
[2021-09-13 18:29:04Z INFO Listener] Runner is built for Windows (X64) - win-x64.
[2021-09-13 18:29:04Z INFO Listener] RuntimeInformation: Microsoft Windows 10.0.17763.
[2021-09-13 18:29:04Z INFO Listener] Version: 2.281.1
[2021-09-13 18:29:04Z INFO Listener] Commit: c8caf59
[2021-09-13 18:29:04Z INFO Listener] Culture: en-US
[2021-09-13 18:29:04Z INFO Listener] UI Culture: en-US
[2021-09-13 18:29:04Z INFO HostContext] Well known directory 'Bin': 'C:\runners\win_runner_1\bin'
[2021-09-13 18:29:04Z INFO HostContext] Well known directory 'Root': 'C:\runners\win_runner_1'
[2021-09-13 18:29:04Z INFO Listener] Validating directory permissions for: 'C:\runners\win_runner_1'
[2021-09-13 18:29:04Z INFO CommandLineParser] Parse
[2021-09-13 18:29:04Z INFO CommandLineParser] Parsing 2 args
[2021-09-13 18:29:04Z INFO CommandLineParser] parsing argument
[2021-09-13 18:29:04Z INFO CommandLineParser] HasArgs: False
[2021-09-13 18:29:04Z INFO CommandLineParser] Adding Command: configure
[2021-09-13 18:29:04Z INFO CommandLineParser] parsing argument
[2021-09-13 18:29:04Z INFO CommandLineParser] HasArgs: True
[2021-09-13 18:29:04Z INFO CommandLineParser] arg: version
[2021-09-13 18:29:04Z INFO Listener] Arguments parsed
[2021-09-13 18:29:04Z INFO Runner] ExecuteCommand
[2021-09-13 18:29:04Z INFO ConfigurationStore] currentAssemblyLocation: C:\runners\win_runner_1\bin\Runner.Listener.dll
[2021-09-13 18:29:04Z INFO HostContext] Well known directory 'Bin': 'C:\runners\win_runner_1\bin'
[2021-09-13 18:29:04Z INFO ConfigurationStore] binPath: C:\runners\win_runner_1\bin
[2021-09-13 18:29:04Z INFO HostContext] Well known directory 'Bin': 'C:\runners\win_runner_1\bin'
[2021-09-13 18:29:04Z INFO HostContext] Well known directory 'Root': 'C:\runners\win_runner_1'
[2021-09-13 18:29:04Z INFO ConfigurationStore] RootFolder: C:\runners\win_runner_1
[2021-09-13 18:29:04Z INFO HostContext] Well known directory 'Bin': 'C:\runners\win_runner_1\bin'
[2021-09-13 18:29:04Z INFO HostContext] Well known directory 'Root': 'C:\runners\win_runner_1'
[2021-09-13 18:29:04Z INFO HostContext] Well known config file 'Runner': 'C:\runners\win_runner_1.runner'
[2021-09-13 18:29:04Z INFO ConfigurationStore] ConfigFilePath: C:\runners\win_runner_1.runner
[2021-09-13 18:29:04Z INFO HostContext] Well known directory 'Bin': 'C:\runners\win_runner_1\bin'
[2021-09-13 18:29:04Z INFO HostContext] Well known directory 'Root': 'C:\runners\win_runner_1'
[2021-09-13 18:29:04Z INFO HostContext] Well known config file 'Credentials': 'C:\runners\win_runner_1.credentials'
[2021-09-13 18:29:04Z INFO ConfigurationStore] CredFilePath: C:\runners\win_runner_1.credentials
[2021-09-13 18:29:04Z INFO HostContext] Well known directory 'Bin': 'C:\runners\win_runner_1\bin'
[2021-09-13 18:29:04Z INFO HostContext] Well known directory 'Root': 'C:\runners\win_runner_1'
[2021-09-13 18:29:04Z INFO HostContext] Well known config file 'MigratedCredentials': 'C:\runners\win_runner_1.credentials_migrated'
[2021-09-13 18:29:04Z INFO ConfigurationStore] MigratedCredFilePath: C:\runners\win_runner_1.credentials_migrated
[2021-09-13 18:29:04Z INFO HostContext] Well known directory 'Bin': 'C:\runners\win_runner_1\bin'
[2021-09-13 18:29:04Z INFO HostContext] Well known directory 'Root': 'C:\runners\win_runner_1'
[2021-09-13 18:29:04Z INFO HostContext] Well known config file 'Service': 'C:\runners\win_runner_1.service'
[2021-09-13 18:29:04Z INFO ConfigurationStore] ServiceConfigFilePath: C:\runners\win_runner_1.service
[2021-09-13 18:29:04Z INFO CommandSettings] Flag 'help': 'False'
[2021-09-13 18:29:04Z INFO CommandSettings] Flag 'version': 'True'
[2021-09-13 18:29:04Z INFO Terminal] WRITE LINE: 2.281.1
[2021-09-13 18:29:04Z INFO Listener] Runner execution has finished with return code 0

@olivier-jourdan
Copy link

I have the same behavior on my self-hosted windows runner 😞

Execute the following action

     - run: ls
     shell: bash

gives the following error

Run ls
  ls
  shell: C:\Windows\system32\bash.EXE --noprofile --norc -e -o pipefail {0}
/bin/bash: C:actions-runner_work_temp9928f894-24aa-42cc-b75c-7cc78ff93ccc.sh: No such file or directory

PowerShell can execute bash, but it seems that the runner cannot find it.
I didn't find any documentation describing how to invoke bash from the runner.
Any help would be very welcome.

I'd appreciate any help anybody can provide.

@nikola-jokic nikola-jokic self-assigned this Mar 9, 2022
@nikola-jokic
Copy link
Member

Hi @olivier-jourdan,

You can invoke it with:

name: CI

on:
  workflow_dispatch:
  
jobs:
  build:
    runs-on: windows-latest
    steps:
      - name: bash
        shell: bash
        run: ls -la

@ruvceskistefan
Copy link
Collaborator

Hi @brian-pickens, @olivier-jourdan,
I'm trying to reproduce the reported bug, but this problem doesn't happen on my self-hosted windows runner.
These are steps of my action from the workflow file:

- name: working-dir
   shell: bash
   run: echo $PWD
- name: make-dir
   shell: bash
   run: mkdir test_folder
- name: list
   shell: bash
   run: ls

As you can see, I created steps with $PWD and commands like mkdir and ls, and I didn't get that error.

The following image shows the output of my action:
image0

Can you check if you still get that error on the newer version of the runner?

@ChristopherHX
Copy link
Contributor

Can you check if you still get that error on the newer version of the runner?

It still happens, but only if you use C:\Windows\System32\bash.exe, the windows subsystem for linux bash.

  • The wsl bash comes with the windows subsystem for linux feature
  • The wsl bash calls the original bash executable of ubuntu from windows, without converting any input parameter
  • The wsl bash shell doesn't accept any windows style path with \ or drive prefix C: only linux style path are valid like /mnt/c/Users/
  • The wsl bash is always in your PATH variable on windows systems

You cannot reproduce it with a mingw, msys or cygwin bash shell in your PATH ( only if it is found before searching in the system32 directory ), which you have installed through git for windows.

@ruvceskistefan
Copy link
Collaborator

Hi @ChristopherHX,
Thanks for the explanation, now I understand. However, if you use windows-latest in the workflow file for hosting runner, you may notice that bash is on the path C:\Program Files\Git\bin\bash.EXE and not C:\Windows\System32\bash.EXE. Based on that I would say that the expected behavior is the use of git bash, not windows subsystem for Linux bash.
Therefore, I will label this as an enhancement and runner feature and add it to the enhancement backlog, so we will implement wsl support in the future.

@ruvceskistefan ruvceskistefan added enhancement New feature or request Runner Feature Feature scope to the runner labels Mar 15, 2022
@nikola-jokic nikola-jokic removed the bug Something isn't working label Apr 4, 2022
@FaiqueAli
Copy link

Hi, at the moment I am also facing the exact same issue.
I also set up the environment variable(git bash) for system in my runner but still simple hello world command is not working on bash.
looking for the help..

@onbjerg
Copy link

onbjerg commented Jun 28, 2022

@ruvceskistefan For some reason when spawning bash -c <...> from a Rust binary the WSL version of bash is used and an error is returned saying no WSL distribution is installed, but I would expect it to use the Git bash version. Any guidance on why the behavior is different?

For more context I am using actions-rs/cargo@v1 to run cargo test. Inside one of my tests I spawn bash -c "echo -n xyz" and I assert that stdout is equal to xyz.

Edit: This is on windows-latest. Also, we are not able to use a fully qualified path for separate reasons.

@brian-pickens
Copy link
Author

brian-pickens commented Jun 28, 2022

Hi @brian-pickens, @olivier-jourdan, I'm trying to reproduce the reported bug, but this problem doesn't happen on my self-hosted windows runner. These are steps of my action from the workflow file:

- name: working-dir
   shell: bash
   run: echo $PWD
- name: make-dir
   shell: bash
   run: mkdir test_folder
- name: list
   shell: bash
   run: ls

As you can see, I created steps with $PWD and commands like mkdir and ls, and I didn't get that error.

The following image shows the output of my action: image0

Can you check if you still get that error on the newer version of the runner?

Unfortunately we are no longer using a windows runner so I'm unable to test. However I don't believe your test case is valid. In our case we were passing a path the step ENV property, which was consumed by the terraform cli to execute. However it appeared that the path that was actually passed to the ENV variable contained none of the forward slashes.

The other difference I noticed is that I was using windows subsystem for linux on the host machine while you are using GIT Bash.

@wilg
Copy link

wilg commented Sep 20, 2022

Does anyone know how to use Git Bash in a Windows runner if WSL is installed? It seems like it isn't part of PATH and there's no way to map bash to Git Bash.

@PavanMudigondaTR
Copy link

Could someone please help. I am having exact same issue !

@PavanMudigondaTR
Copy link

PavanMudigondaTR commented Sep 22, 2022

I was able to solve this by uninstalling Ubuntu, WSL 2 feature and then by restarting runner. Now only Git Bash is there so it started working ! any one facing this problem can workaround this way until GitHub can implement WSL Bash support ! I wish GitHub can improve documentation so we don't have to struggle things much !

@markphip
Copy link

markphip commented Mar 6, 2023

You can recreate this problem by using a self-hosted Windows runner that has WSL enabled. I wonder if the GitHub runner could be updated to not rely upon PATH to find bash.exe and instead execute using the bash provided by Git for Windows?

@mlekoo
Copy link

mlekoo commented Mar 9, 2023

If you won't use wsl anyways, you should add git bash directory to your path env variable.
image
You can check if is it working by trying "where bash" in cmd, it should show you the path to git.
image

@Azuna1
Copy link

Azuna1 commented Mar 9, 2023

make sure to move the git entry to the top if you still find the WSL version

@Augustukas
Copy link

It helped me to install WSL wsl --install

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Runner Feature Feature scope to the runner
Projects
None yet
Development

No branches or pull requests