Can I use pip to install a package from a private VSTS repository?

自古美人都是妖i 提交于 2021-02-18 06:36:49

问题


I would like to install a private package for my python app with pip.

My package is stored in a git repo on Azure DevOps (Visual Studio Team Services).

I see that git is supported by pip, but I cannot determine a workable format for the URL for Azure.

I would like to avoid the Credential Manager. I have tried both git+ssh (with key) and git+https (with Personal Access Token).

Is it possible to do this with Azure/VSTS?

For context, I referenced these resources:

https://www.revsys.com/tidbits/using-private-packages-python/

Is it possible to use pip to install a package from a private github repository?

Here are some of my attempts:

git+https://myUsername:myAccessToken@myCompany.visualstudio.com/myProject/_git/myPackage.git
git+https://<myAccessToken>@visualstudio.com/<myCompany>/<myProject>.git@<ref>
git+https://<myUsername>:<myAccessToken>@<myCompany>.visualstudio.com/<myteam>/<myProject>.git@<ref>
git+https://<myUsername>:<myAccessToken>@visualstudio.com/<myCompany>/<myProject>.git@<ref>
git+https://<myUsername>:<myAccessToken>@visualstudio.com/<myCompany>/<myProject>.git@<ref>
git+ssh://myCompany@vs-ssh.visualstudio.com:v3/myCompany/<myProject>.git@<ref>

回答1:


It is possible, please have a look it to this existing Request

As per that, you need to follow the below steps,

  • Check the Allow script to access the OAuth token in the Agent job phase
  • Include the Task: command Line
  • Add $(System.AccessToken) between repo clone URL

This above is the System variable, you can find the full details here

You can also use the Rest API like below for getting the access token

$url = "$($env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI)$env:SYSTEM_TEAMPROJECTID/_apis/build-release/definitions/$($env:SYSTEM_DEFINITIONID)?api-version=2.0"
Write-Host "URL: $url"
$pipeline = Invoke-RestMethod -Uri $url -Headers @{
    Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN"
}
Write-Host "Pipeline = $($pipeline | ConvertTo-Json -Depth 1000)"


来源:https://stackoverflow.com/questions/53181349/can-i-use-pip-to-install-a-package-from-a-private-vsts-repository

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!