最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Execute Python code with GitLab parallel matrix in different OS (Windows and Linux) - Stack Overflow

programmeradmin2浏览0评论

I'd like to test my project's code with e2e tests, hopefully in different OS to ensure it works as expected not only in Linux systems but in other ones as well.

To achieve this, I'd like to use GitLab's parallel:matrix so I can manage my tests in a single place, without having to declare a new job for each new OS I'd like to add.

So far, this is what I have in mind:

stages: [test]

test:e2e:
  stage: test
  image:
    name: $PYTHON_IMAGE

  tags:
    - $RUNNER_TAG

  parallel:
    matrix:
      - OS: linux
        PYTHON_IMAGE: python:3.11-slim
        RUNNER_TAG: saas-linux-small-arm64

      - OS: windows
        PYTHON_IMAGE: python:3.11-windowsservercore-ltsc2022
        RUNNER_TAG: saas-windows-medium-amd64

  script:
    - python --version

However, this is NOT possible because GitLab's hosted Windows runners do not use Docker like Linux runners. This means that the saas-windows-medium-amd64 doesn't have Python installed in it, thus failing whenever trying to execute any Python code in it:

$ python --version
python : The term 'python' is not recognized as the name of a cmdlet, function, script file, or operable program. 
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:286 char:1
+ python --version
+ ~~~~~~
    + CategoryInfo          : ObjectNotFound: (python:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

The solution I've thought is to install Python through chocolatey whenever running in a windows OS. However, because Windows has its own syntax I can't find any possible way to manage this within my job's script section.

I expect to execute Python code in a GitLab parallel:matrix with different OS (Windows and Linux). To achieve this, I've tried to use GitLab's hosted official runners. However, Windows runners do not use Docker in them, thus I can't specify which image the runner will be using.

发布评论

评论列表(0)

  1. 暂无评论