actions / runner

The Runner for GitHub Actions :rocket:
https://github.com/features/actions
MIT License
4.74k stars 922 forks source link

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

Open brian-pickens opened 2 years ago

brian-pickens commented 2 years ago

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: c8caf59bb7adaa87c4cf8f61372670d338a13f2d [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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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.

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 commented 2 years ago

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.

FaiqueAli commented 2 years ago

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 commented 2 years ago

@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 commented 2 years ago

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 commented 1 year ago

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 commented 1 year ago

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

PavanMudigondaTR commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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

Augustukas commented 7 months ago

It helped me to install WSL wsl --install