pythonlinuxazure-devopsazure-devops-self-hosted-agent

Azure DevOps Pipeline Agent.ToolsDirectory error on self-hosted agent LINUX- RHEL 9 while setting up python under Tool Cache


I have a self-hosted agent that has Python3.9.18 installed which comes as part of RHEL 9 Image. Everytime I run the pipeline I get an error.

##[error]Version spec 3.9 for architecture x64 did not match any version in Agent.ToolsDirectory.
Versions in /home/<user>/myagent/_work/_tool:
<BLANK>

I have created the folder structure as well

/myagent/_work/_tool/Python/3.9/x64/<tool files> and x64.complete but still no success it doesn't find anything underneath "Agent.ToolsDirectory"

environment variable has been set.

echo $Agent.ToolsDirectory
/home/<user>/myagent/_work/_tool

Could you recommend some options to consider?

What needs to be done for the tool files? What are these files?

Tried options :

I am trying to use this task UsePythonVersion@0.


Solution

  • I tested in my self-hosted agent. I can reproduce the issue when I use the version 3.9 in the path.

    In the official document How can I configure a self-hosted agent to use this task?, it mentions that

    The version number should follow the format of 1.2.3.

    As a complete and concrete example, here is how a completed download of Python 3.11.4 for x64 would look in the tool cache:

    $AGENT_TOOLSDIRECTORY/
        Python/
            3.11.4/
               x64/
                   {tool files}
               x64.complete
    

    So, you should change the /myagent/_work/_tool/Python/3.9/x64/<tool files> to /myagent/_work/_tool/Python/3.9.18/x64/<tool files>.

    Update:

    You can download the python package version you need in the python-versions releases page or python-versions tags page and unzip it as the {tool files}.

    For example:

    enter image description here

    The x64.complete file is not in the x64 folder.

    You can also use the following yaml to check the python files in the Microsoft hosted agent.

    pool:
      vmImage: ubuntu-latest
    
    steps:
    - task: UsePythonVersion@0
      inputs:
        versionSpec: '3.9' 
        architecture: 'x64' 
    - bash: tree  $(Agent.ToolsDirectory)/Python/3.9.19
    - task: CopyFiles@2
      inputs:
        SourceFolder: '$(Agent.ToolsDirectory)/Python/3.9.19'
        Contents: '**'
        TargetFolder: '$(Build.ArtifactStagingDirectory)'
    - task: PublishBuildArtifacts@1
      inputs:
        PathtoPublish: '$(Build.ArtifactStagingDirectory)'
        ArtifactName: 'drop'
        publishLocation: 'Container'
    

    The published artifact content:

    enter image description here