DJ *_*ijk 6 c# nuget build-pipeline devops
我正在尝试检查我们的构建管道之一中是否有过时的软件包。使事情变得复杂的是,我们使用来自 nuget.org 的包以及来自我们自己的存储库(DevOps 工件提要)的包。这些源在 nuget.config 中配置。包恢复任务成功,没有任何问题:
- task: NuGetCommand@2
displayName: Restore Nuget Packages
inputs:
command: 'restore'
restoreSolution: '**/*.sln'
feedsToUse: 'config'
nugetConfigPath: 'nuget.config'
Run Code Online (Sandbox Code Playgroud)
在此步骤之后,我们安装 dotnet-outdated-tool:
- task: DotNetCoreCLI@2
displayName: install dotnet-outdated-tool
inputs:
command: 'custom'
custom: 'tool'
arguments: 'install dotnet-outdated-tool -g --ignore-failed-sources'
Run Code Online (Sandbox Code Playgroud)
请注意,我们已经在此处添加了 --ignore-failed-sources 选项,否则该工具将无法正确安装,因为它会抱怨我们的提要无法访问,但我们可以通过添加 --ignore-failed-sources 来通过。
接下来,也是关于我的问题的最重要的一步,是我们尝试运行过时的工具来检查过时的软件包:
- task: DotNetCoreCLI@2
displayName: Check outdated packages
inputs:
command: 'custom'
custom: 'outdated'
arguments: '$(pathTosolution)'
env:
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
Run Code Online (Sandbox Code Playgroud)
对于 nuget.org 中的软件包,这似乎工作正常:
Microsoft.Extensions.DependencyInjection 5.0.0 -> 5.0.1
Microsoft.NET.Test.Sdk 16.7.1 -> 16.9.1
MSTest.TestAdapter 2.1.1 -> 2.2.1
Run Code Online (Sandbox Code Playgroud)
对于我们自己的源中的包,它无法解析最新版本:
Some.Internal.Component 1.22.0 ->
Run Code Online (Sandbox Code Playgroud)
它还提到:
Errors occurred while analyzing dependencies for some of your projects. Are you sure you can connect to all your configured NuGet servers?
Run Code Online (Sandbox Code Playgroud)
所以很明显它无法连接到我们的内部 nuget feed。尝试通过将系统访问令牌添加到任务中来解决它: SYSTEM_ACCESSTOKEN: $(System.AccessToken) 但不幸的是,这并不能解决任何问题。我缺少什么????
我们最终通过在 nuget.config 中注入 PAT 来解决这个问题
powershell:
- task: PowerShell@2
inputs:
pwsh: true
targetType: 'inline'
script: |
echo 'Adding tokens'
foreach($line in Get-Content nuget.config) {
if($line -match 'key=\"(?<key>[^\"]+)\"\s*value=\"(?<value>[^\"]+)\"'){
if($Matches.key -notmatch 'nuget.org') {
echo $Matches.key
nuget sources remove -name $Matches.key
nuget sources add -name $Matches.key -source $Matches.value -username anything -password $(System.AccessToken)
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
959 次 |
| 最近记录: |