4

There is the following simple pipeline:
buildtestdeploy
that uses specified python version for all stages, for example 3.8.

How can I scale (parametrize) it for python with versions: 3.7, 3.8 and 3.9?
Simplest solution that comes to mind is to create 3 different pipelines with hardcoded python versions:
build_37test_37deploy_37
build_38test_38deploy_38
build_39test_39deploy_39.

I know this is a very bad solution.
What is the right way?

1
  • 1
    this sounds like a pretty cut-and-dry use case for Tox - have you tried that? Sep 21, 2021 at 13:51

3 Answers 3

2

I would suggest to use the parallel matrix feature of GitLab CI (see also here). As Bruce Becker suggested utilizing tox is also a valid option and exactly designed for your use case.

build:
  image: python:${PY_VERSION}
  parallel:
    matrix:
      - PY_VERSION: ["3.7", "3.8", "3.9"]
  script: poetry build
1

One could use Gitlab templates in conjunction with an environment variable that sets the python version.

0

You can parametrize GitLab pipeline using variables keyword in gitlab-ci.yaml:

variables:
  PYTHON_VERSION:
    value: "3.7"
    options:
      - "3.7"
      - "3.8"
      - "3.9"
    description: "Python version"

You can see a sample GitLab gitlab-ci.yaml using variables keyword at my GitLab or read an article about GitLab Parameterized Pipelines.

Disclaimer: I wrote the above article.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.