Skip to content

Ensure shell script only writes file variables if they don't exist

What does this MR do?

When writing a file variable, it now checks if the file already exists before writing the contents.

Why was this MR needed?

The Kubernetes Windows executor appears to have trouble sometimes writing over existing files as they may be open by other processes.

Line |
  68 |  [System.IO.File]::WriteAllText($ExecutionContext.SessionState.Path.Ge …
     |  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Exception calling "WriteAllText" with "2" argument(s): "Access to the path 'C:\builds\3ucBgYkQ\0\ajwalker\windows-playground.tmp\CI_SERVER_TLS_CA_FILE' is denied."

This simply ensures that if the file exists, we don't write it again. File variables shouldn't be possible to change between stages, so the fact it's not overwritten shouldn't be an issue.

What's the best way to test this MR?

I don't think we need additional tests. This is more an implementation detail, and we already have tests that ensure the file variable has been written.

A manual test:

Manual QA:

  • Setup a Windows k8s cluster on GCP.
  • Authenticate locally with gcloud container clusters get-credentials <cluster name>
  • Configure runner's config.toml
    [[runners]]
    ...
    executor = "kubernetes"
    shell = "pwsh"
    
    [runners.feature_flags]
      # If deploying the Runner to Linux, but targetting Windows, this FF needs to be enabled for now
      FF_USE_POWERSHELL_PATH_RESOLVER = true
    
      # Our newer execution strategy doesn't yet support Windows pods
      FF_USE_LEGACY_KUBERNETES_EXECUTION_STRATEGY = true
    [runners.kubernetes]
      image = "mcr.microsoft.com/powershell:lts-nanoserver-1809"
      [runners.kubernetes.node_selector]
        "kubernetes.io/arch" = "amd64"
        "kubernetes.io/os" = "windows"
        "node.kubernetes.io/windows-build" = "10.0.17763"
  • Run any simple job. Before this change, an access denied error will be present.

What are the relevant issue numbers?

Closes #27710 (closed)

Edited by Arran Walker

Merge request reports