Add support for Powershell Core (investigation and analysis)
Description
Gitlab Runner currently only supports Windows batch and Windows PowerShell on Windows platforms. Recently Microsoft introduced PowerShell 6 (Core) which can run indifferently on Linux or Windows: https://docs.microsoft.com/en-us/powershell/scripting/powershell-scripting?view=powershell-6
This new PowerShell doesn't overwrite the pre-installed Powershell (v5.x) on Windows systems, but runs alongside the old version, thus requiring the user to launch Powershell Core with a different command than previously. The new executable is named "pwsh" and can be launched with the "pwsh" command if the PATH environment variable is correctly set to point to Powershell Core's installation path.
Setting the PATH variable using PowerShell :
[Environment]::SetEnvironmentVariable("PATH", "$env:PATH;C:\Program Files\Powershell\6.0.2", [EnvironmentVariableTarget]::Machine)
%12.9 milestone
The goal for the %12.9 milestone to understand, investigate what needs to be done for us to add PowerShell core support, either by providing a PoC or having some kind of MVC ready and better answers to the following questions:
- What needs to happen to support both Linux/Windows?
- What needs to happen to support Docker executor Linux/Windows?
- What needs to happen to support Kubernetes executor to use pwsh?
- What is the upgrade path for users?
Proposal
Executors
- Allow user to specify
pwshas a shell, which will use thepowershellshell writer, but instead of invokingpowershellinvokepwsh. Something similar to what we do inbashandshjust no fallback. There is WIP merge request !1855 (closed). The reason for having a new shell the user has to configured instead of just usingpowershellis because if we makepowershelljust use PowerShell 6/7 out of the box if its available we are going to end up breaking existing scripts for users that expect to use PowerShell 5, like this users need to be aware of the change they make. -
pwshaccepts both/and\in the path for Unix based systems, butgitdoesn't accept them. When we use the powershell script generator we use\since that is the acceptable version for Windows. This leads to problems like this fails CI job. In !1855 (diffs) we extend the Extend the ShellWriter interface and implement aJoinfunction to extend the which will set the correct slash depending on script type and call it instead ofpath.Join. Another way to do this is don't covert to backslash ifpwshis chosen. - We use
$env:computernameto print out the first line of the jobRunning on ...,$env:computernamedoesn't seem available on Unix pwsh, so have some kind of fallback environment such ashostname.
Shell Executor #13134 (closed)
With the points above the shell executor should work out of the box, apart from some git failures which we need to fix the path generation.
Docker Executor Windows #13139 (closed)
- Update the Windows helper image to have pwsh installed and also PowerShell 5 installed, for example !1855 (diffs)
- Update https://gitlab.com/gitlab-org/gitlab-runner/-/blob/058d0c5e98afbb54eb2d12614ed73b563109038c/docs/executors/docker.md#L52-56 to make it clear that users can use
nanoservernow.
Docker Executor Linux #4021 (closed)
- Have
dockerexecutor choose betweenpwshandbashdepending on the userconfig.toml. We need to remove any assumptions we have that we are using abashshell. - Update the linux helper image to have pwsh
installed.
One thing to consider is how much of size increase there would be by
having pwsh installed since this container is used multiple times, it
might be worth having a separate image just for
pwshand then have the executor chooses the right image. - Somehow update
gitlab-runner-build
or the usage of it to support both bash and
pwshso it doesn't mess up helper image commands.
Kubernetes #13145 (closed)
- Have
kubernetsexecutor choose betweenpwshandbashdepending on the userconfig.toml. We need to remove any assumptions we have that we are using abashshell.
Development environment
- Update Vagrant box to have PowerShell 6 installed. !1848 (merged)
Plan to migrate from PowerShell 5 to PowerShell core
- Have dual support for PowerShell 5 and PowerShell 6/7 up till 14.0
- In 14.0 have
pwshthe default shell, instead ofpowershell - In 15.0 completely remove
powershelland only allowpwshwhich would be PowerShell core.
Possible follow up issues
-
Update our helper image to use nanoserver instead of servercore when
you use
pwsh(backwords compatibility needs to be considered for users still using PowerShell 5). This should make our builds faster instead of starting a 4GB container it will be around 1GB of a container. This can also bring some maintenance cost if we need to support both PowerShell 5 and PowerShell 6, since we would have to keep the servercore helper images up to date as well.
Dev log
2020-02-17
- Set up the environment to have powershell 6 installed
- Hardcode Runner to use
pwshwhenpowershellis specified as a shell. - Test simple job on Windows
- Test simple job in Linux
- Start investigating the scope of the issue
2020-02-18
- Get !1848 (merged) in a mergeable state, required me to change how we provision our environment !1853 (merged)
- Start with Extend the ShellWriter interface and implement a
Joinfunction to extend the which will set the correct slash depending on script type and call it instead ofpath.Jointo validate the idea. - With !1855 (closed) we manage to get a job running on Linux with
pwshwith some warnings.
2020-02-19
-
Run job on Windows Docker executor
- Update helper image to have
pwshavailable
- Rung job with `windows-docker` executorgit diff
diff --git a/dockerfiles/build/Dockerfile.x86_64_servercore1809 b/dockerfiles/build/Dockerfile.x86_64_servercore1809 index 8c48126ab..f4e50a4b6 100644 --- a/dockerfiles/build/Dockerfile.x86_64_servercore1809 +++ b/dockerfiles/build/Dockerfile.x86_64_servercore1809 @@ -22,7 +22,7 @@ RUN powershell -File .\checksum.ps1 -TargetFile git-lfs.zip -ExpectedHash ${Env: RUN Expand-Archive -Path git.zip -DestinationPath git RUN Expand-Archive -Path git-lfs.zip -DestinationPath git-lfs -FROM mcr.microsoft.com/windows/servercore:1809_amd64 +FROM mcr.microsoft.com/powershell:6.2.3-windowsservercore-1809.gitlab-ci.yml
job: image: mcr.microsoft.com/powershell/6.2.3-windowsservercore-1809 script: - echo $PSVersionTable.PSVersion - Update helper image to have
2020-02-20
- Investigate kubernetes executor with pwsh
- We need update the executor to support multiple shells
- Update the helper command
gitlab-runner-buildto usepwshorbashdepending on the shell.
- Update proposal