Skip to content

Enable PowerShell Core support in Kubernetes Executor

Pedro Pombeiro requested to merge 13145-pwsh-in-k8s-executor into master

What does this MR do?

It makes the necessary changes for the Kubernetes executor and Powershell shell to support the pwsh shell value and use the correct helper image.

Why was this MR needed?

See #13145 (closed)

What's the best way to test this MR?

  1. Start a Kubernetes dev cluster locally with minikube (minikube start)

  2. Switch the Docker client to the Kubernetes cluster:

    eval $(minikube docker-env)
  3. Build the helper image and Runner so it is available in minikube's Docker daemon image cache:

    make helper-dockerarchive-host runner-bin-host
  4. Register a Runner to run builds on the local cluster (define $YOUR_TOKEN):

    gitlab-runner register --executor "kubernetes" --kubernetes-image mcr.microsoft.com/powershell --url "https://gitlab.com/" --description "kubernetes-runner" --tag-list "kubernetes,gitlab.com,pwsh" --locked="false" --access-level="not_protected" --registration-token="<your token>" --non-interactive
  5. Start the runner:

    out/binaries/gitlab-runner run
  6. Create a pipeline with the following .gitlab-ci.yml:

    start_evaluation:
      image: mcr.microsoft.com/powershell
      script:
        - Get-Host
      tags: [kubernetes, pwsh]
  7. The pipeline should pass, as seen in this job

    Job log
    Running with gitlab-runner 13.9.0~beta.65.g4262cecd (4262cecd)
      on Kubernetes executor zqMtkFxL
    Resolving secrets
    00:00
    Preparing the "kubernetes" executor
    00:00
    WARNING: Namespace is empty, therefore assuming 'default'.
    Using Kubernetes namespace: default
    WARNING: Pulling GitLab Runner helper image from Docker Hub. Helper image is migrating to registry.gitlab.com, for more information see https://docs.gitlab.com/runner/configuration/advanced-configuration.html#migrating-helper-image-to-registrygitlabcom
    Using Kubernetes executor with image mcr.microsoft.com/powershell ...
    Preparing environment
    00:04
    Waiting for pod default/runner-zqmtkfxl-project-16892582-concurrent-0sfltt to be running, status is Pending
    Running on runner-zqmtkfxl-project-16892582-concurrent-0sfltt via 
    pedros-macbookpro16.home.pombei.ro...
    Getting source from Git repository
    00:03
    Fetching changes with git depth set to 50...
    Initialized empty Git repository in /builds/pedropombeiro/playground/.git/
    Created fresh repository.
    Checking out cb4bb3d5 as k8s-pwsh-test...
    git-lfs/2.11.0 (GitHub; linux amd64; go 1.13.11; git fceccfb7bd)
    Skipping Git submodules setup
    Executing "step_script" stage of the job script
    00:01
    $ Get-Host
    Name             : ConsoleHost
    Version          : 7.1.1
    InstanceId       : 20d09587-e70f-4fb7-9164-1eeafbb3aac2
    UI               : System.Management.Automation.Internal.Host.InternalHostUserI
                       nterface
    CurrentCulture   : en-US
    CurrentUICulture : en-US
    PrivateData      : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
    DebuggerEnabled  : True
    IsRunspacePushed : False
    Runspace         : System.Management.Automation.Runspaces.LocalRunspace
    Cleaning up file based variables
    00:00
    Job succeeded

What are the relevant issue numbers?

Closes #13145 (closed)

Edited by Pedro Pombeiro

Merge request reports