我有一个 Azure DevOps 管道。我需要从两个单独的源恢复,不包括 nuget.org。第一个是 Azure 项目中的工件源,另一个是来自 JFrog 源的外部工件源。我在完成它时遇到了一些困难。我能想到的唯一方法是使用 NuGet.Config 文件,如下所示:
steps:
# Find and set NuGet.config file path to disco2000 variable
- task: PowerShell@2
inputs:
targetType: 'inline'
script: Write-Host "##vso[task.setvariable variable=disco2000]$(Get-ChildItem $env:APPDATA/NuGet/NuGet.Config)"
# Add internal feed to NuGet.config
- task: NuGetCommand@2
displayName: 'Add internal Feed'
inputs:
command: 'custom'
arguments: 'sources Add -Name internal -Source https://internal/url/to/an/index.json -username anything -password $(System.AccessToken)'
# Add external feed to NuGet.config
- task: NuGetCommand@2
displayName: 'Add external Feed'
inputs:
command: 'custom'
arguments: 'sources Add -Name external -Source https://external/url/to/an/index.json -username $(feedUsername) -password $(feedPassword)'
- task: NuGetCommand@2
inputs:
command: 'restore'
restoreSolution: '$(solution)'
feedsToUse: 'config'
nugetConfigPath: '$(disco2000)'
feedUsername
和feedPassword
都来自蔚蓝的密钥库。像这样手动添加外部提要很好,只有某些管道需要访问它,但问题是我无法访问项目自己的工件提要和我提出的解决方案,将其添加单独的任务,对我来说就像一个黑客。
有更好的方法吗?
您可以将外部 feed 添加为项目内 feed 的上游源。请参阅设置上游源的详细信息。