Skip to content

Windows Runner in Kubernetes: ERROR: Preparation failed: kubernetes doesn't support shells that require script file

Summary

In the process of trying to debug a Windows Runner in Kubernetes issue - when using GitLab Runner 14.9.0 (Chart version 0.39.0) - with a simple Runner configuration and simple CI/CD build script on a self-managed GitLab 14.9.2-ee installation - I'm seeing the following error in jobs:

Using Kubernetes namespace: gitlab-runner-windows
Using Kubernetes executor with image mcr.microsoft.com/windows/servercore:ltsc2019 ...
Using attach strategy to execute scripts...
ERROR: Preparation failed: kubernetes doesn't support shells that require script file
Will be retried in 3s ...

This is before the Pod is ever created on the Windows node.

This error does not occur on Runner version 14.8.2 (Chart version 0.38.1) or earlier.

Steps to reproduce

Deploy a Helm based GitLab Runner using Chart version 0.39.0 to a GKE-cluster (Kubernetes version v1.21.6-gke.1503)

Use the following values:

gitlabUrl: <gitlab host>
runnerRegistrationToken: "<token>"
logLevel: 'debug'
rbac:
  create: true
runners:
  namespace: gitlab-runner-windows
  tags: "i-k8s-win"
  config: |
    [[runners]]
      environment = ["FF_USE_POWERSHELL_PATH_RESOLVER=1"]
      [runners.kubernetes]
        image = "mcr.microsoft.com/windows/servercore:ltsc2019"
      [runners.kubernetes.node_selector]
      	"kubernetes.io/arch" = "amd64"
      	"kubernetes.io/os" = "windows"
        "node.kubernetes.io/windows-build" = "10.0.17763"
      [runners.kubernetes.dns_config]
      [runners.kubernetes.container_lifecycle]

And a simple .gitlab-ci.yml:

stages:
  - build_stage

build:
    tags:
        - i-k8s-win
    variables:
        CI_DEBUG_TRACE: "true"
    stage: build_stage
    script:
        - echo "Building_Dummy_job"
        - Get-Date -format s
        - sleep 100
        - Get-Date -format s
        - echo "Dummy_job_built"

Actual behavior

Job execution results in:

ERROR: Preparation failed: kubernetes doesn't support shells that require script file

Possible fixes

It seems like this may be potentially due to the logic change for PassFile and pwsh introduced in Allow changing shell executor with pwsh user (!3298 - merged) - I noticed that error message comes from this line

	if s.BuildShell.PassFile {
		return fmt.Errorf("kubernetes doesn't support shells that require script file")
	}

And we changed the logic of how that's set in Allow changing shell executor with pwsh user (!3298 - merged)

That's the only change I could find that might have led to this.