如何解决从构建脚本推送到工件的nuget未能通过身份验证
我有一个用FAKE编写的构建脚本,我想在devops管道下运行。 该版本可以通过我的笔记本电脑运行。 我有YAML来触发和运行该构建,它可以构建,但是无法将工件推送到nuget存储库中。
我已经生成了一个PAT,并在NuGetPublish调用中(现在是明确地)使用了它。
NuGet.NuGetPublish
(fun p ->
{
p with
Project = name
Version = version
PublishUrl = "https://...../nuget/v3/index.json"
WorkingDir = "."
OutputPath = path
AccessKey = "bla bla bla"
}))
这可以在我的笔记本电脑上工作,但是在Azure上,它仅重试并重新绑定...
NugetPublish from..
NugetPublish from..D:\a\1\s\US.2018r2.000.024.Schema\bin\Release\US.2018r2.000.024.Schema.1.1.2.nupkg
name=US.2018r2.000.024.Schema
version=1.1.2
path=D:\a\1\s\US.2018r2.000.024.Schema\bin\Release
Starting task 'NuGet-Push': US.2018r2.000.024.Schema.1.1.2.nupkg
D:\a\1\s\tools\NuGet\nuget.exe push "D:\a\1\s\US.2018r2.000.024.Schema\bin\Release\US.2018r2.000.024.Schema.1.1.2.nupkg" -ApiKey <NuGetKey> -Source https://pkgs.dev.azure.com/Kookerella2/_packaging/Kookerella2/nuget/v3/index.json -Timeout 300 in WorkingDir: D:\a\1\s Trials left: 5
.> "D:\a\1\s\tools\NuGet\nuget.exe" push "D:\a\1\s\US.2018r2.000.024.Schema\bin\Release\US.2018r2.000.024.Schema.1.1.2.nupkg" -ApiKey <NuGetKey> -Source https://pkgs.dev.azure.com/Kookerella2/_packaging/Kookerella2/nuget/v3/index.json -Timeout 300 (In: false,Out: false,Err: false)
CredentialProvider.VSS: Getting new credentials for source:https://pkgs.dev.azure.com/Kookerella2/_packaging/Kookerella2/nuget/v3/index.json,scope:vso.packaging_write vso.drop_write
CredentialProvider.VSS: Getting new credentials for source:https://pkgs.dev.azure.com/Kookerella2/_packaging/Kookerella2/nuget/v3/index.json,scope:vso.packaging_write vso.drop_write
D:\a\1\s\tools\NuGet\nuget.exe push "D:\a\1\s\US.2018r2.000.024.Schema\bin\Release\US.2018r2.000.024.Schema.1.1.2.nupkg" -ApiKey <NuGetKey> -Source https://pkgs.dev.azure.com/Kookerella2/_packaging/Kookerella2/nuget/v3/index.json -Timeout 300 in WorkingDir: D:\a\1\s Trials left: 4
“正在获取新的凭据”等等等
我知道您可以从管道任务中进行发布,但是我只是想从Jenkins进行移植,我非常喜欢构建脚本要做的很多事情,而管道却不是很多。 / p>
----修正---
进一步挖掘似乎ApiKey几乎毫无意义,您需要使用类似...
nuget sources add -name "Kookerella2" -source https://pkgs.dev.azure.com/..../index.json -username anything -password [PAT]
现在只需通过使用由yaml驱动的“脚本”来明确尝试即可。
----有效,请参见下文(直到明天我才能将其标记为答案)------
唯一的悬而未决的问题是……在YAML中放入PAT密钥不好……我应该怎么做?
我尝试过
- script: nuget sources add -name "Kookerella2" -source https://pkgs.dev.azure.com/..../index.json -username anything -password %sYstem_ACCEsstOKEN%
env:
SYstem_ACCEsstOKEN: $(System.Accesstoken)
如果我尝试“ echo%SYstem_ACCEsstOKEN%”,我会得到***...。
解决方法
因此答案是忽略API密钥,它什么也不做,您需要将对Nuget的访问权授予存储库。
我通过从devops创建新的PAT密钥来使用PAT密钥
然后在我的Yaml中包含一个脚本。显然,该示例是伪造的PAT。
name: $(Rev:r)
trigger:
- master
jobs:
- job: Windows
pool:
vmImage: 'windows-2019'
steps:
- task: NuGetToolInstaller@1
- task: UseDotNet@2
inputs:
packageType: 'sdk'
version: '3.1.201'
- script: dotnet tool restore
displayName: Install FAKE
- script: nuget sources add -name "ACME" -source https://pkgs.dev.azure.com/ACME/_packaging/ACME/nuget/v3/index.json -username anything -password 5xxxxxxxxxxxq
displayName: nuget add source
- script: dotnet fake build
displayName: Run Build
这可行!...但是...我认为在YAML中使用PAT密钥不是一种好习惯。
,错误指示NuGet在连接到Azure DevOps程序包Feed时会不断提示输入凭据。
这意味着您登录时使用的帐户无权访问NuGet软件包。
一旦授予访问权限,您就应该能够登录,然后它将按预期工作。
但是...我认为在YAML中使用PAT密钥不是一个好习惯。
是的,这不是安全和推荐的方法。相反,您可以使用变量,变量组或Azure Keyvault来保护您的PAT,并在管道中使用它。。
详细说明官方文档如何使用variable group作为参考,只需将其保密即可。
此外,正如 Krzysztof Madej 所说,您还可以直接传递OAuth令牌,而无需维护单独的PAT。
更多详细信息,请查看此blog。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。