How to specify 'os' for free gitlab runners ('runs-on' equivalent) How can I specify the operating system in the .gitlab-ci file to indicate which underlying OS on which the gitlab-runner should be running when using the 2,000 minutes of free execution in with gitlab.com shared runners in Google Cloud Platform?

For context, Github's free account supports 2,000 free minutes per month in "Github-hosted runners" for running Github Actions in Azure and MacStadium. You can specify whether you want the build to happen in Linux, Windows, or MacOS via the runs-on key in the github workflow yaml file.

What is the equivalent method for specifying that I want to run a CI/CD job in a specific OS on GCP in the .gitlab-ci file?
You can specify that you want gitlab to execute your CI job on a windows machine using tags.

Gitlab made Windows Shared Runners available as Beta in Jan 2020. Their announcement shows how to use the tags key in your .gitlab-ci file to specify Windows machines. You can also run in a docker container in windows:


https://docs.gitlab.com/runner/executors/docker.html#using-windows-containers


For example, I was able to execute a simple "hello world" powershell script with the following job in my .gitlab-ci file:

windows:
  script: "build/windows/buildExe.ps1"
  tags:
    - shared-windows
    - windows
    - windows-1809


And here's the buildExe.ps1 powershell script reference above:

Write-Host "listing contents of C drive root"
Get-ChildItem -Path C:\ -Force

Write-Host "listing contents of cwd"
Get-ChildItem -Force


The above config produced the following output in my CI job:

[0KRunning with gitlab-runner 12.9.0 (4c96e5ad)
[0;m[0K  on windows-shared-runners-manager 6QgxEPvR
[0;msection_start:1590842482:prepare_executor
[0K[0K[36;1mPreparing the "custom" executor[0;m
[0;m[0KUsing Custom executor with driver autoscaler dev (64a348d)...
[0;mCreating virtual machine for the job...
Virtual machine created!
section_end:1590842624:prepare_executor
[0Ksection_start:1590842624:prepare_script
[0K[0K[36;1mPreparing environment[0;m
[0;mRunning on PACKER-5E557E8E via 
runner-6qgxepvr-wsrm-87cf700a3349de62a18e...
section_end:1590842640:prepare_script
[0Ksection_start:1590842640:get_sources
[0K[0K[36;1mGetting source from Git repository[0;m
[0;m[32;1mFetching changes with git depth set to 50...[0;m
Initialized empty Git repository in C:/GitLab-Runner/builds/maltfield/cross-platform-python-gui/.git/
[32;1mCreated fresh repository.[0;m
[32;1mChecking out 91f0d9e3 as master...[0;m
From https://gitlab.com/maltfield/cross-platform-python-gui
 * [new ref]         refs/pipelines/151176370 -&gt; refs/pipelines/151176370
 * [new branch]      master                   -&gt; origin/master
git-lfs/2.8.0 (GitHub; windows amd64; go 1.12.2; git 30af66bb)

[32;1mUpdating/initializing submodules...[0;m
git-lfs/2.8.0 (GitHub; windows amd64; go 1.12.2; git 30af66bb)
section_end:1590842661:get_sources
[0Ksection_start:1590842661:restore_cache
[0K[0K[36;1mRestoring cache[0;m
[0;msection_end:1590842670:restore_cache
[0Ksection_start:1590842670:download_artifacts
[0K[0K[36;1mDownloading artifacts[0;m
[0;msection_end:1590842677:download_artifacts
[0Ksection_start:1590842677:build_script
[0K[0K[36;1mRunning before_script and script[0;m
[0;m[32;1m$ build/windows/buildExe.ps1[0;m
listing contents of C drive root


    Directory: C:\


Mode                LastWriteTime         Length Name                                                                  
----                -------------         ------ ----                                                                  
d--hs-       12/11/2019   2:47 AM                $RECYCLE.BIN                                                          
d--hs-        2/25/2020   8:52 PM                Boot                                                                  
d--hsl       12/11/2019  10:29 AM                Documents and Settings                                                
d-----        2/25/2020   8:16 PM                Git                                                                   
d-----        5/30/2020  12:44 PM                GitLab-Runner                                                         
d-----        2/25/2020   8:16 PM                GitLFS                                                                
d-----        2/25/2020   8:34 PM                Go                                                                    
d-----        9/15/2018   7:12 AM                PerfLogs                                                              
d-r---        2/25/2020   8:35 PM                Program Files                                                         
d-----        2/25/2020   8:27 PM                Program Files (x86)                                                   
d--h--        2/25/2020   8:51 PM                ProgramData                                                           
d--hs-        2/25/2020   8:10 PM                Recovery                                                              
d--hs-       12/11/2019  10:28 AM                System Volume Information                                             
d-----        2/25/2020   8:32 PM                tools                                                                 
d-r---        5/30/2020  12:43 PM                Users                                                                 
d-----        2/25/2020   8:38 PM                vcpkg                                                                 
d-----        2/25/2020   8:51 PM                Windows                                                               
-arhs-        2/25/2020   8:45 PM         408834 bootmgr                                                               
-a-hs-        9/15/2018   7:09 AM              1 BOOTNXT                                                               
-a-hs-        5/30/2020  12:41 PM     1073741824 pagefile.sys                                                          
listing contents of cwd


    Directory: C:\GitLab-Runner\builds\maltfield\cross-platform-python-gui


Mode                LastWriteTime         Length Name                                                                  
----                -------------         ------ ----                                                                  
d--h--        5/30/2020  12:44 PM                .git                                                                  
d-----        5/30/2020  12:44 PM                build                                                                 
d-----        5/30/2020  12:44 PM                src                                                                   
-a----        5/30/2020  12:44 PM            534 .gitlab-ci.yml                                                        
-a----        5/30/2020  12:44 PM          35787 LICENSE                                                               
-a----        5/30/2020  12:44 PM           1171 README.md                                                             
-a----        5/30/2020  12:44 PM              6 requirements.txt                                                      


section_end:1590842686:build_script
[0Ksection_start:1590842686:archive_cache
[0K[0K[36;1mSaving cache[0;m
[0;msection_end:1590842694:archive_cache
[0Ksection_start:1590842694:upload_artifacts_on_success
[0K[0K[36;1mUploading artifacts for successful job[0;m
[0;msection_end:1590842701:upload_artifacts_on_success
[0K[32;1mJob succeeded
[0;m


As for MacOS, gitlab currently doesn't support it natively. If this changes, updated answers are welcome.

Other answers showing how to run MacOS inside a VM (eg using vagrant and libvirt) on a gitlab shared runner are very welcome :)