- 1 year ago
Gitlab CI: How to use the bash shell on a Windows runner
In GitLab CI, when using a Windows runner, the default shell is PowerShell. However, if you prefer to use the bash shell on a Windows runner, you can achieve that by explicitly specifying the shell in your GitLab CI configuration file (.gitlab-ci.yml
).
To use the bash shell on a Windows runner, follow these steps:
Install Git Bash on the Windows Runner:
Git Bash provides a bash shell for Windows systems. You can download and install it on your Windows runner machine. Ensure that Git Bash is added to the system PATH so that it can be accessed from any location.Specify the Shell in
.gitlab-ci.yml
:
In your GitLab CI configuration file (.gitlab-ci.yml
), specify that you want to use the bash shell as the shell for your CI job by setting theshell
keyword under thevariables
section. For example:
yamlvariables:
SHELL: "C:\\Program Files\\Git\\bin\\bash.exe"
In this example, we assume that Git Bash is installed in the default location (C:\Program Files\Git\bin\bash.exe
). Adjust the path accordingly if you installed it in a different location.
- Use Bash Commands in CI Jobs:
Now, you can use bash commands in your CI job scripts. For example:
yamlstages:
- build
build_job:
stage: build
script:
- echo "This is a bash command in a Windows runner"
- ls -l # Example bash command
With the SHELL
variable set to the path of Git Bash, the CI job will use bash as the shell for executing the job's script.
Remember that specifying the shell as bash in a Windows runner is optional. PowerShell is the default shell on Windows runners and is fully supported for running CI jobs. However, if you prefer to use bash for any reason, you can set it explicitly as shown above.
Keep in mind that the availability and behavior of certain commands or scripts may differ between PowerShell and bash. Make sure to test your CI jobs thoroughly when using a different shell to ensure compatibility with your specific use case.