What shall I use for the input 'githubToken' of Azure DevOps Pipeline task UsePythonVersion@0
Asked Answered
A

3

6

I have a self-hosted Azure DevOps Pipeline build agent and would like to download and install Python from the Github repository if it is not already available in the agent tools directory.

The official documentation for the Azure DevOps pipeline task UsePythonVersion@0 states about the input 'githubToken':

githubToken: # string. Optional. Use when disableDownloadFromRegistry = false GitHub token for GitHub Actions python registry.

I am not familiar with GitHub actions and am confused regarding what I should provide for the githubToken input. It is a PAT? Or does it refer to the GITHUB_TOKEN? Where shall I obtain such token so that my pipeline can successfully download Python from GitHub.

The error I experience at the moment is:

##[error]Failed to download Python from the Github Actions python registry (https://github.com/actions/python-versions). Error: Error: unable to get local issuer certificate
Azotic answered 13/12, 2022 at 10:28 Comment(0)
S
2

[error]Failed to download Python from the Github Actions python registry

this error might appear also in case if the file was downloaded, but there were errors with installing python from downloaded ".zip" archive. Thus it is necessary to provide full log and not only name of the error.

Back to your other question. To get a token open "Github.com":

  • press on the upper left icon with your avatar
  • press "Settings" in the drop down
  • On the left in the bottom you'll see "Developer Settings"
  • click on "Personal Access tokens" and create any of two token types

or try this url: https://github.com/settings/tokens?type=beta

Sceptre answered 24/1, 2023 at 12:11 Comment(1)
Where can one find the full log? BTW, I know how to create a PAT in Github, that is not the question.Azotic
K
1

This task will fail if no Python versions are found in Agent.ToolsDirectory.

To use this task with self-hosted agent, you could follow this link.

First, you could download the appropriate installer from Python.org

I downloaded python-3.7.9-amd64.exe for test.

Then you could run command line (CMD run as administrator) to install the python python-3.7.9-amd64.exe /quiet InstallAllUsers=0 TargetDir={agentinstallPath\_work\_tool}\Python\3.7.9\x64 Include_launcher=0

enter image description here

Remember to switch to the folder which contains python-3.7.9-amd64.exe enter image description here

At last, you need to create an empty {platform}.complete file.

$AGENT_TOOLSDIRECTORY/
    Python/
        {version number}/
            {platform}/
                {tool files}
            {platform}.complete

enter image description here

After restarting the self-hosted agent, pipeline run well.

steps:
- task: UsePythonVersion@0
  displayName: 'Use Python 3.7.9'
  inputs:
    versionSpec: 3.7.9
Kristlekristo answered 13/12, 2022 at 16:4 Comment(5)
I understand that one can install Python manually the way you describe. But my understanding is that by setting the disableDownloadFromRegistry to false one can download automatically from the GitHub registry This is what I am trying to achieve. My understanding is that I then need to provide the githubToken input.Azotic
You could follow this to create a personal access token for Github.githubTokenKristlekristo
Please confirm that your python version is available for windows or linux. Python versions-manifestKristlekristo
You could follow this to create a personal access token for Github.And add it to githubToken in task. githubToken steps: - task: UsePythonVersion@0 displayName: 'Use Python 3.6.8' inputs: versionSpec: 3.6.8 githubToken: '$(githubToken)' Kristlekristo
Sorry for not mentionning this earlier, but the error shown in my original post is with version 3.x, platform set to default (x64) and githubToken: '$(PAT)'Azotic
E
0

This might only apply for the Microsoft hosted agents.

  1. Create a Github action token here https://github.com/settings/personal-access-tokens/new
  2. Create a secret variable storing the GithubAction token https://learn.microsoft.com/en-us/azure/devops/pipelines/process/set-secret-variables?view=azure-devops&tabs=yaml%2Cbash
  3. Pass the token as variable to the UsePythonVersion in your Azure pipeline https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/reference/use-python-version-v0?view=azure-pipelines

steps:
- task: UsePythonVersion@0
  displayName: 'Use Python 3.14'
  inputs:
    versionSpec: 3.14
    disableDownloadFromRegistry: false # allow downloading from registry.
    allowUnstable: true # allow upcoming releases (candidates, betas etc).
    githubToken: $(myGithubToken) # this should be the name of your toke variable!
Enallage answered 2/10 at 9:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.