I want to start matrix testing for my code. I try running unit test using the yml below on Azure Devops pipelines.
When I run it, it shortens "3.10" to "3.1". How do I avoid that?
parameters:
- name: imageList
type: object
default: ["windows-latest", "ubuntu-latest", "windows-2019", "ubuntu-20.04"]
- name: pythonList
type: object
default:
- "3.11"
- "3.10" # WHAT TO DO HERE
- "3.9"
stages:
- stage: test_on_microsoft_hosted_agents
jobs:
- ${{ each image in parameters.imageList }}:
- job: ${{ replace(replace(image, '-', '_'), '.', '_') }}
pool:
vmImage: ${{ image }}
strategy:
maxParallel: 1
matrix:
${{ each python in parameters.pythonList }}:
Python${{ replace(python, '.', '') }}:
python.version: "${{ python }}"
platform.name: "${{ image }}"
steps:
- task: UsePythonVersion@0
inputs:
versionSpec: "$(python.version)"
displayName: "Use Python $(python.version)"
3
Answers
Try specifying using the format function to ensure that the version string remains intact
I try avoiding as much formatting etc work in azure pipelines as possible as it can get cursed, its typically easier (from my experience) to scan the parameter and then toggle a classic matrix based on those values.
The way I would implement this python versioning strategy is as follows:
This also removes all the formatting and splitting malarky, and is the way azure recommends handling this versioning stuff
This is a dirty workaround, but consider adding a prefix to the version number to force it to be treated as a string, instead of a number.
Instead of:
Do:
Prefix
v
can be easily removed when setting the version inUsePythonVersion@0
task.Example
Running the pipeline: