GitLab CI shared Windows runner for Python

Viewed 872

I have a python project repo in GitLab. I saw that GitLab has shared Windows runner in beta version available (See this post).

I am wondering if there is any standard gitlab-ci.yml for python on Windows shared runner? If so, since this is still beta version, I'm curious how stable is this? For those who have used this and have experience with AppVeyor, am I better off with AppVeyor or this?

Thanks!

2 Answers

You can use this snippet:

my_win_job:
  before_script:
    # https://gitlab.com/gitlab-org/ci-cd/shared-runners/images/gcp/windows-containers/-/issues/13
    - Import-Module "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1"
    - choco install python3 --version=$PYTHON_VERSION --yes --force --no-progress
    - refreshenv
  script:
    - python -V
    - python -m pip install -U pip wheel
  variables:
    PYTHON_VERSION: "3.9"
  tags:
    - windows

I hope it's still relevant but you can use chocolatey to install python on the virtual machine gitlab windows runners create, like the next .gitlab-ci.yml example:

.shared_windows_runners:
   tags:
     - shared-windows
     - windows
     - windows-1809

before_script:
  - Set-Variable -Name "time" -Value (date -Format "%H:%m")
  - echo ${time}
  - echo "started by ${GITLAB_USER_NAME}"
  - choco install python --version=3.7.0 -y -f

stages:
  - build

build_somthing:
  extends:
    - .shared_windows_runners
  stage: build
  script:
    - "C:\\Python37\\python.exe -m pip install --upgrade setuptools"
    - "C:\\Python37\\python.exe -m pip install -r requirements.txt"

chocolatey will install python in path: C:\Python37, so if you want to use python you can use it as follows: "C:\Python37\python.exe -m pip install --upgrade setuptools"

Related