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
pwsh
as a shell, which will use thepowershell
shell writer, but instead of invokingpowershell
invokepwsh
. Something similar to what we do inbash
andsh
just no fallback. There is WIP merge request !1855 (closed). The reason for having a new shell the user has to configured instead of just usingpowershell
is because if we makepowershell
just 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. -
pwsh
accepts both/
and\
in the path for Unix based systems, butgit
doesn'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 aJoin
function 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 ifpwsh
is chosen. - We use
$env:computername
to print out the first line of the jobRunning on ...
,$env:computername
doesn't seem available on Unix pwsh, so have some kind of fallback environment such ashostname
.
#13134 (closed)
Shell ExecutorWith 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.
#13139 (closed)
Docker Executor Windows- 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
nanoserver
now.
#4021 (closed)
Docker Executor Linux- Have
docker
executor choose betweenpwsh
andbash
depending on the userconfig.toml
. We need to remove any assumptions we have that we are using abash
shell. - 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
pwsh
and then have the executor chooses the right image. - Somehow update
gitlab-runner-build
or the usage of it to support both bash and
pwsh
so it doesn't mess up helper image commands.
#13145 (closed)
Kubernetes- Have
kubernets
executor choose betweenpwsh
andbash
depending on the userconfig.toml
. We need to remove any assumptions we have that we are using abash
shell.
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
pwsh
the default shell, instead ofpowershell
- In 15.0 completely remove
powershell
and only allowpwsh
which 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
pwsh
whenpowershell
is 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
Join
function to extend the which will set the correct slash depending on script type and call it instead ofpath.Join
to validate the idea. - With !1855 (closed) we manage to get a job running on Linux with
pwsh
with some warnings.
2020-02-19
-
Run job on Windows Docker executor
- Update helper image to have
pwsh
available
git 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-build
to usepwsh
orbash
depending on the shell.
- Update proposal