azure-devopsyamlazure-pipelinesazure-yaml-pipelines

YML How to specify python 3.10


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? enter image description here

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)"

Solution

  • The behavior seemed to be reported here. I also tried to use split() function but it didn't seem to work as replace() as suggested by @RUI.

    Since the versionSpec property of the UsePythonVersion@0 uses SemVer's version range syntax,

    A leading "=" or "v" character is stripped off and ignored.

    Thus, we can use v3.10 as the python version in the UsePythonVersion task directly.

    parameters:
      - name: imageList
        type: object
        default: ["windows-latest", "ubuntu-latest", "windows-2019", "ubuntu-20.04"]
      - name: pythonList
        type: object
        default:
        - 'v3.11'
        - 'v3.10' # WHAT TO DO HERE
        - 'v3.9'
    
    stages:
      - stage: test_on_microsoft_hosted_agents
        jobs:
          - ${{ each image in parameters.imageList }}:
            - job: ${{ replace(replace(image, '-', '_'), '.', '_') }}
              pool:
                vmImage: ${{ image }}
              strategy:
                maxParallel: 10
                matrix:
                  ${{ each python in parameters.pythonList }}:
                    Python${{ replace(python, '.', '') }}:
                      python.version: ${{python}} # Use v3.x directly
                      platform.name: ${{ image }}
              steps:
                - script: |
                    echo $(python.version)
    
                - task: UsePythonVersion@0
                  inputs:
                    versionSpec: '$(python.version)'
                  displayName: Use Python $(python.version)
    

    Image