Custom Executor into Windows VM (Using Linux KVM/libvirt)

Hey, I have a Linux machine that I’ve got a couple VMs on. I’m using the libvirt example given in:

and it works great for my Linux VMs. I’ve also set up a Windows Server 2022 VM and installed on my dependencies on it. I’ve set up key-based SSH login to this machine that also works great. The difference seems to be that when I SSH into the Windows machine I get the cmd shell. So I’ve updated my runners config to be:

  name = "win2022-vm"
  url = "https://gitlab"
  token = "xxxx"
  executor = "custom"
  shell = "cmd"
  builds_dir = "c:\\builds"
  cache_dir = "c:\\cache"
    prepare_exec = "/vms/scripts_win2022/"
    run_exec = "vms/scripts_win2022/"
    cleanup_exec = "vms/scripts_win2022/"

It still seems to be SSHing into the Windows machine with the wrong shell:

  on win2022-vm epb-hs2X
Resolving secrets
Preparing the "custom" executor
Using Custom executor...
Formatting '/vms/runner-1232-project-2316-concurrent-0-job-919213.qcow2', fmt=qcow2 size=214748364800 backing_file='/vms/win2022.qcow2' backing_fmt='qcow2' encryption=off cluster_size=65536 lazy_refcounts=off 
Starting install...
Domain creation completed.
Waiting for VM to get IP
VM got IP:
Waiting for sshd to be available
Preparing environment
The system cannot find the path specified.
ERROR: Job failed: prepare environment: exit status 1. Check for more information

Any ideas? Thanks!

I discovered that I was still using the /bin/bash command to the SSH call in the script. Oops. I changed it to cmd.exe and had it freeze up while trying to call git clone. I decided to bite the bullet and go to PowerShell 7 where it now says:

Preparing environment
PowerShell 7.2.5
Copyright (c) Microsoft Corporation.
Type 'help' to get help.
PS C:\Users\Administrator> echo "Running on $([Environment]::MachineName)..."
echo: The term 'echo' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
PS C:\Users\Administrator> 

If I SSH into the machine and type echo I get it aliased to Write-Output as expected…

PowerShell 7.2.5
Copyright (c) Microsoft Corporation.
Type 'help' to get help.

PS C:\Users\Administrator> echo

cmdlet Write-Output at command pipeline position 1
Supply values for the following parameters:

Output when SSHing directly:

PS C:\Users\Administrator> echo "Running on $([Environment]::MachineName)..."     
Running on WIN-KD6KPVQHACJ... on host:

#!/usr/bin/env bash

currentDir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
source ${currentDir}/ # Get variables from base script.


ssh -i /root/.ssh/id_rsa -o StrictHostKeyChecking=no Administrator@"$VM_IP" pwsh.exe < "${1}"
if [ $? -ne 0 ]; then
    # Exit using the variable, to make the build as failure in GitLab
    # CI.

I’m basically talking to the rubber ducky :stuck_out_tongue: I switched the shell in the config.toml to pwsh to match the fact that I’m using PowerShell 7. Now it freezes at the same spot as the cmd shell, trying to create the certifcate in c:\builds\tmp:

>> [System.IO.File]::WriteAllText("$CurrentDirectory/c:/builds/group/repo.tmp/CI_SERVER_TLS_CA_FILE", "-----BEGIN CERTIFICATE-----`nMIIGwTCCBamgAwIBAgIQIr2XWQH/Ti2wTUU4auG......

It looks like the script that is passed to pwsh.exe in the SSH command is cut short…is there such a thing as it being too long? It’s cut off part way through dumping the certifcate:

ssh -i /root/.ssh/id_rsa -o StrictHostKeyChecking=no Administrator@ pwsh.exe
PowerShell 7.2.5
Copyright (c) Microsoft Corporation.
Type 'help' to get help.
PS C:\Users\Administrator> #!/usr/bin/env pwsh
PS C:\Users\Administrator> & {
>> $ErrorActionPreference = "Stop"
more until we get to dumping the cert

then gets cut off. Since it’s not even sending the full Command-Let (or whatever pwsh speak is for the script) after & nothing gets executed and it hangs.

Definitely running into a character limit. I thought PowerShell didn’t have the same limit that cmd.exe did?