Skip to content

Avoid errors when creating files in pwsh 2.0

What does this MR do?

Avoid errors when creating files in PowerShell 2.0 (for instance, on windows 7).

In PowerShell 2.0, it looks like setting an -ItemType when calling New-Item is mandatory, otherwise the command will fail with the following error:

New-Item : Windows PowerShell is in NonInteractive mode. Read and Prompt functionality is not available.
At C:\Windows\temp\kubevirt_gitlab_runner-get_sources-PT6xzE.ps1:496 char:92
+ if(!(Test-Path "\tmp\gitlab-runner\builds\group\repo.tmp\gitlab_runner_env")) { New-Item <<<<  -Force "\tmp\gitlab-runner\builds\group\repo.tmp\gitlab_runner_env" | out-null }
    + CategoryInfo          : InvalidOperation: (:) [New-Item], PSInvalidOperationException
    + FullyQualifiedErrorId : InvalidOperation,Microsoft.PowerShell.Commands.NewItemCommand

Why was this MR needed?

We use a windows7 runner to test our software's compatibility with Windows 7. This works fine, but some of the steps generate a ton of noise because of the above error. Note that this error isn't a hard error somehow, the job continues fine, but each time it tries to access gitlab_runner_env, it will create some more noise complaining about its nonexistence... and move right along.

I also suspect (though haven't confirmed) that it means the jobs would not have access to the environment variables set by the runner.

What's the best way to test this MR?

Run a job in a job in a powershell runner. To confirm the bug is fixed, you'll need a powershell 2.0 runner, which can be acquired in a Windows 7 VM.

What are the relevant issue numbers?

Merge request reports