首页 > 解决方案 > 我可以使用 pip 从私有 VSTS 存储库安装包吗?

问题描述

我想用 pip 为我的 python 应用程序安装一个私有包。

我的包存储在Azure DevOps (Visual Studio Team Services) 上的 git 存储库中。

我看到pip 支持 git,但我无法确定 Azure 的 URL 的可行格式。

我想避免使用Credential Manager。我已经尝试过 git+ssh(带密钥)和 git+https(带个人访问令牌)。

是否可以使用 Azure/VSTS 执行此操作?

对于上下文,我参考了以下资源:

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

是否可以使用 pip 从私有 github 存储库安装包?

以下是我的一些尝试:

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>

标签: gitpipazure-devops

解决方案


有可能,请看一下这个现有的请求

据此,您需要按照以下步骤操作,

  • 在代理作业阶段检查允许脚本访问 OAuth 令牌
  • 包括任务:命令行
  • $(System.AccessToken)在 repo 克隆 URL 之间添加

以上是系统变量,您可以在此处找到完整的详细信息

您还可以使用如下所示的 Rest API 来获取访问令牌

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

推荐阅读