无法从 Azure DevOps Artifact Feed 访问 Chocolatey 包
Cannot access Chocolatey package from Azure DevOps Artifact Feed
流动代码已被推送到 Azure DevOps Artifacts Feed:
推送 nuget 包并使用 nuget.exe 下载工作没有问题:
nuget.exe push -Source "cdrtools-artifacts" -ApiKey AzureDevOps schily-cdrtools.3.2.1.nupkg
nuget.exe install -Source "cdrtools-artifacts" schily-cdrtools
但是,使用 v2 或 v3 nuget 注册尝试使用 Chocolatey 注册此源会导致 404 错误:
choco source add -n=schily-artifacts `
>> -s="https://flapjacks.pkgs.visualstudio.com/_packaging/schily-artifacts/nuget/v3/index.json" `
>> -u="xxxxxxxx" -p="xxxxxxxxxxx"
Error retrieving packages from source 'https://flapjacks.visualstudio.com/_packaging/schily-artifacts/nuget/v3/index.json':
The remote server returned an error: (404) Not Found.
schily-cdrtools not installed. The package was not found with the source(s) listed.
Source(s): 'https://flapjacks.visualstudio.com/_packaging/schily-artifacts/nuget/v3/index.json'
NOTE: When you specify explicit sources, it overrides default sources.
If the package version is a prerelease and you didn't specify `--pre`,
the package may not be found.
Please see https://chocolatey.org/docs/troubleshooting for more
assistance.
...使用 v2 时出现相同的 404 错误:
choco source add -n=schily-artifacts `
>> -s="https://flapjacks.pkgs.visualstudio.com/_packaging/schily-artifacts/nuget/v2" `
>> -u="xxxxxxxx" -p="xxxxxxx"
尝试使用 v2 注册列表时未找到任何包,但是当 运行 使用 v3 注册 choco 列表时返回 404 错误。
最后,尝试使用 Install-Package 失败并出现凭据问题:
Install-Package schily-cdrtools
WARNING: Cannot access 'https://flapjacks.pkgs.visualstudio.com/_packaging/schily-artifacts/nuget/v3/index.json'. Are you missing 'Credential' parameter in the cmdlet?
Install-Package : No match was found for the specified search criteria and package name 'schily-cdrtools'. Try Get-Packa
geSource to see all available registered package sources.
At line:1 char:1
+ Install-Package schily-cdrtools
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Microsoft.PowerShel\u2026lets.InstallPackage:InstallPackage) [Install-Package
], Exception
+ FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage
有什么想法没有我想念的吗?
我一直在使用以下内容作为指导:
https://blog.pauby.com/post/chocolatey-repository-using-azure-devops-artifacts-feed/
PackageManagement cmdlet 目前已损坏,因此在没有 -Credential
参数的情况下使用 Install-Package
将失败。您需要将 -Credential
参数添加到所有 PackageManagement cmdlet 才能使它们正常工作。
如果我运行(完全):
choco source add -n=schily-artifacts -s="https://flapjacks.pkgs.visualstudio.com/_packaging/schily-artifacts/nuget/v2" -u="xxxxxxxx" -p="xxxxxxxxxxx"
然后我得到:
Chocolatey v0.10.15
Added schily-artifacts - https://flapjacks.pkgs.visualstudio.com/_packaging/schily-artifacts/nuget/v2 (Priority 0)
Chocolatey 在您使用 Feed 之前不会验证它:
choco list --source=schily-artifacts
Chocolatey v0.10.15
Invalid credentials specified.
Invalid credentials specified.
Invalid credentials specified.
Invalid credentials specified.
Invalid credentials specified.
Invalid credentials specified.
Invalid credentials specified.
Invalid credentials specified.
[NuGet] Not able to contact source 'https://flapjacks.pkgs.visualstudio.com/_packaging/schily-artifacts/nuget/v2'. Error was The remote server returned an error: (401) Unauthorized.
Invalid credentials specified.
Invalid credentials specified.
Invalid credentials specified.
Invalid credentials specified.
Invalid credentials specified.
Invalid credentials specified.
Invalid credentials specified.
Invalid credentials specified.
[NuGet] Not able to contact source 'https://flapjacks.pkgs.visualstudio.com/_packaging/schily-artifacts/nuget/v2'. Error was The remote server returned an error: (401) Unauthorized.
0 packages found.
这是我所期望的(因为凭据无效)。所以我不确定你在添加源时的错误来自哪里。
Cannot access Chocolatey package from Azure DevOps Artifact Feed
根据该指南中的步骤创建示例后,我无法重现此问题。但我想为您提供一些故障排除方法:
- 检查你的 Chocolatey 版本,我的是
Chocolatey v0.10.15
。
- 添加名为 source 的 Chocolatey Azure DevOps Feed 时使用 PAT 而不是密码。
- 运行 带管理员的命令行。
命令行要完整,不需要分支,如:
choco source add -n=MyCustomFeed -s="https://pkgs.dev.azure.com/<MyOrgName>/_packaging/<FeedName>/nuget/v2" -u="MyAccount.com" -p="PAT"
我的测试结果:
希望这对您有所帮助。
使用 Credential Provider 的另一种方法,对 github.com/chocolatey/choco/issues/1721 中发布的脚本稍作修改(最后几行更改为使用 choco
而不是nuget
命令)。
该脚本运行一个 Credential Provider(提示您登录到 Azure DevOps 并自动生成一个 PAT)。返回的 PAT 与
中相同的 choco 命令一起使用
param (
[Parameter(Mandatory=$true)]
[string]$feedName,
[Parameter(Mandatory=$true)]
[string]$url
)
$profilePath = [System.Environment]::GetFolderPath([System.Environment+SpecialFolder]::UserProfile)
$pluginLocation = [System.IO.Path]::Combine($profilePath, ".nuget", "plugins");
$localNetfxCredProviderPath = [System.IO.Path]::Combine("netfx", "CredentialProvider.Microsoft");
$fullNetfxCredProviderPath = [System.IO.Path]::Combine($pluginLocation, $localNetfxCredProviderPath)
$netfxExists = Test-Path -Path ($fullNetfxCredProviderPath)
if($netfxExists -eq $false)
{
Write-Host "Installing credential provider..."
iex "& { $(irm https://aka.ms/install-artifacts-credprovider.ps1) } -AddNetfx"
$netfxExists = Test-Path -Path ($fullNetfxCredProviderPath)
if($netfxExists -eq $false)
{
Write-Host "Credentials provider is required."
Write-Host "Maybe install manually from https://github.com/microsoft/artifacts-credprovider/releases"
return
}
}
$exe = [System.IO.Path]::Combine($fullNetfxCredProviderPath, 'CredentialProvider.Microsoft.exe')
# It's not possible to disable device based authentication, but we can set timeout to fail immidiately.
$ENV:NUGET_CREDENTIALPROVIDER_VSTS_DEVICEFLOWTIMEOUTSECONDS=0
# Validity period: 1 year. (Can have larger value)
$ENV:NUGET_CREDENTIALPROVIDER_VSTS_SESSIONTIMEMINUTES=365*24*60
# '-V Error' is required not to get extra messages
$msg = & $exe -V Error -U $url -C -F JSON 2>&1 | Out-String
if($lastexitcode -ne 0)
{
Write-Host
Write-Host "$msg"
Write-Host
Write-Host "Failed to run '$exe' ($lastexitcode)"
return
}
try
{
$info = ConvertFrom-Json $msg
}
catch
{
Write-Host
Write-Host "$msg"
Write-Host
return
}
choco source add -v -n="$feedName" -s="$url" -u "$($info.Username)" -p="$($info.Password)"
流动代码已被推送到 Azure DevOps Artifacts Feed:
推送 nuget 包并使用 nuget.exe 下载工作没有问题:
nuget.exe push -Source "cdrtools-artifacts" -ApiKey AzureDevOps schily-cdrtools.3.2.1.nupkg
nuget.exe install -Source "cdrtools-artifacts" schily-cdrtools
但是,使用 v2 或 v3 nuget 注册尝试使用 Chocolatey 注册此源会导致 404 错误:
choco source add -n=schily-artifacts `
>> -s="https://flapjacks.pkgs.visualstudio.com/_packaging/schily-artifacts/nuget/v3/index.json" `
>> -u="xxxxxxxx" -p="xxxxxxxxxxx"
Error retrieving packages from source 'https://flapjacks.visualstudio.com/_packaging/schily-artifacts/nuget/v3/index.json':
The remote server returned an error: (404) Not Found.
schily-cdrtools not installed. The package was not found with the source(s) listed.
Source(s): 'https://flapjacks.visualstudio.com/_packaging/schily-artifacts/nuget/v3/index.json'
NOTE: When you specify explicit sources, it overrides default sources.
If the package version is a prerelease and you didn't specify `--pre`,
the package may not be found.
Please see https://chocolatey.org/docs/troubleshooting for more
assistance.
...使用 v2 时出现相同的 404 错误:
choco source add -n=schily-artifacts `
>> -s="https://flapjacks.pkgs.visualstudio.com/_packaging/schily-artifacts/nuget/v2" `
>> -u="xxxxxxxx" -p="xxxxxxx"
尝试使用 v2 注册列表时未找到任何包,但是当 运行 使用 v3 注册 choco 列表时返回 404 错误。
最后,尝试使用 Install-Package 失败并出现凭据问题:
Install-Package schily-cdrtools
WARNING: Cannot access 'https://flapjacks.pkgs.visualstudio.com/_packaging/schily-artifacts/nuget/v3/index.json'. Are you missing 'Credential' parameter in the cmdlet?
Install-Package : No match was found for the specified search criteria and package name 'schily-cdrtools'. Try Get-Packa
geSource to see all available registered package sources.
At line:1 char:1
+ Install-Package schily-cdrtools
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Microsoft.PowerShel\u2026lets.InstallPackage:InstallPackage) [Install-Package
], Exception
+ FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage
有什么想法没有我想念的吗?
我一直在使用以下内容作为指导:
https://blog.pauby.com/post/chocolatey-repository-using-azure-devops-artifacts-feed/
PackageManagement cmdlet 目前已损坏,因此在没有 -Credential
参数的情况下使用 Install-Package
将失败。您需要将 -Credential
参数添加到所有 PackageManagement cmdlet 才能使它们正常工作。
如果我运行(完全):
choco source add -n=schily-artifacts -s="https://flapjacks.pkgs.visualstudio.com/_packaging/schily-artifacts/nuget/v2" -u="xxxxxxxx" -p="xxxxxxxxxxx"
然后我得到:
Chocolatey v0.10.15
Added schily-artifacts - https://flapjacks.pkgs.visualstudio.com/_packaging/schily-artifacts/nuget/v2 (Priority 0)
Chocolatey 在您使用 Feed 之前不会验证它:
choco list --source=schily-artifacts
Chocolatey v0.10.15
Invalid credentials specified.
Invalid credentials specified.
Invalid credentials specified.
Invalid credentials specified.
Invalid credentials specified.
Invalid credentials specified.
Invalid credentials specified.
Invalid credentials specified.
[NuGet] Not able to contact source 'https://flapjacks.pkgs.visualstudio.com/_packaging/schily-artifacts/nuget/v2'. Error was The remote server returned an error: (401) Unauthorized.
Invalid credentials specified.
Invalid credentials specified.
Invalid credentials specified.
Invalid credentials specified.
Invalid credentials specified.
Invalid credentials specified.
Invalid credentials specified.
Invalid credentials specified.
[NuGet] Not able to contact source 'https://flapjacks.pkgs.visualstudio.com/_packaging/schily-artifacts/nuget/v2'. Error was The remote server returned an error: (401) Unauthorized.
0 packages found.
这是我所期望的(因为凭据无效)。所以我不确定你在添加源时的错误来自哪里。
Cannot access Chocolatey package from Azure DevOps Artifact Feed
根据该指南中的步骤创建示例后,我无法重现此问题。但我想为您提供一些故障排除方法:
- 检查你的 Chocolatey 版本,我的是
Chocolatey v0.10.15
。 - 添加名为 source 的 Chocolatey Azure DevOps Feed 时使用 PAT 而不是密码。
- 运行 带管理员的命令行。
命令行要完整,不需要分支,如:
choco source add -n=MyCustomFeed -s="https://pkgs.dev.azure.com/<MyOrgName>/_packaging/<FeedName>/nuget/v2" -u="MyAccount.com" -p="PAT"
我的测试结果:
希望这对您有所帮助。
使用 Credential Provider 的另一种方法,对 github.com/chocolatey/choco/issues/1721 中发布的脚本稍作修改(最后几行更改为使用 choco
而不是nuget
命令)。
该脚本运行一个 Credential Provider(提示您登录到 Azure DevOps 并自动生成一个 PAT)。返回的 PAT 与
param (
[Parameter(Mandatory=$true)]
[string]$feedName,
[Parameter(Mandatory=$true)]
[string]$url
)
$profilePath = [System.Environment]::GetFolderPath([System.Environment+SpecialFolder]::UserProfile)
$pluginLocation = [System.IO.Path]::Combine($profilePath, ".nuget", "plugins");
$localNetfxCredProviderPath = [System.IO.Path]::Combine("netfx", "CredentialProvider.Microsoft");
$fullNetfxCredProviderPath = [System.IO.Path]::Combine($pluginLocation, $localNetfxCredProviderPath)
$netfxExists = Test-Path -Path ($fullNetfxCredProviderPath)
if($netfxExists -eq $false)
{
Write-Host "Installing credential provider..."
iex "& { $(irm https://aka.ms/install-artifacts-credprovider.ps1) } -AddNetfx"
$netfxExists = Test-Path -Path ($fullNetfxCredProviderPath)
if($netfxExists -eq $false)
{
Write-Host "Credentials provider is required."
Write-Host "Maybe install manually from https://github.com/microsoft/artifacts-credprovider/releases"
return
}
}
$exe = [System.IO.Path]::Combine($fullNetfxCredProviderPath, 'CredentialProvider.Microsoft.exe')
# It's not possible to disable device based authentication, but we can set timeout to fail immidiately.
$ENV:NUGET_CREDENTIALPROVIDER_VSTS_DEVICEFLOWTIMEOUTSECONDS=0
# Validity period: 1 year. (Can have larger value)
$ENV:NUGET_CREDENTIALPROVIDER_VSTS_SESSIONTIMEMINUTES=365*24*60
# '-V Error' is required not to get extra messages
$msg = & $exe -V Error -U $url -C -F JSON 2>&1 | Out-String
if($lastexitcode -ne 0)
{
Write-Host
Write-Host "$msg"
Write-Host
Write-Host "Failed to run '$exe' ($lastexitcode)"
return
}
try
{
$info = ConvertFrom-Json $msg
}
catch
{
Write-Host
Write-Host "$msg"
Write-Host
return
}
choco source add -v -n="$feedName" -s="$url" -u "$($info.Username)" -p="$($info.Password)"