我在 VSTS 中构建了一个版本,该版本在存储库中的每次提交时都会触发。除了一个例外,一切都很好。
我们不会在每次提交时发布新版本的 nuget 包。因此,我们的 nuget 推送构建步骤失败,并显示 http 状态代码 409。我已配置该步骤,以便它无论如何都可以继续。
由于错误,构建只是“部分成功”。我正在使用构建徽章,它也声明相同(没有上下文)。
如何告诉 VSTS 忽略 409 或仅替换现有包(在 nuget.org 上)?
您无法忽略 VSTS 构建中的 409 错误,也无法替换服务器中现有的包。
我建议您可以在发布中推送包,如果包已存在,则发布失败。
另一种方法是,您可以在构建过程中在推送包之前检查服务器中的包(例如 PowerShell、REST API),并设置推送包任务的条件(自定义条件)。
例如:
更新:
NuGet Push Task 现在支持允许跳过重复项! (只需在 NuGet Push 任务中选中允许跳过重复项选项即可。
使用
-SkipDuplicate
标志(自 NuGet 5.1 起可用):
(5.1+) 如果包和版本已经存在,请跳过它并继续推送中的下一个包(如果有)。
来源:https://learn.microsoft.com/en-us/nuget/reference/cli-reference/cli-ref-push#options
我们在 Azure Pipelines 上遇到重复包的问题。
starian chen-MSFT 提出的解决方案很酷,但需要一些脚本。
我们找到了需要更少努力的解决方案。您可以创建命令行步骤并使用以下参数调用 dotnet nuget Push:
dotnet nuget push $(Build.ArtifactStagingDirectory)/*.nupkg --skip-duplicate --api-key $(Config.NuGetApiKey) --source https://api.nuget.org/v3/index.json
关键是参数 --skip-duplicate,如果包已经存在,它只会跳过它们。
在变量 $(Config.NuGetApiKey) 中定义 NuGet.org 的 API 密钥。您应该将其设置为秘密变量,以便它不会出现在日志中的任何位置。
这是此命令的 YAML:
steps:
- script: |
dotnet nuget push $(Build.ArtifactStagingDirectory)/*.nupkg --skip-duplicate --api-key $(Config.NuGetApiKey) --source https://api.nuget.org/v3/index.json
failOnStderr: true
displayName: 'Publish NuGet Package'
我在 dotnet Push 方面的运气为零 - 这是我的背景:
并且始终生成唯一的 preRelease semVer..(这是上述 dotnet pack 的 yaml 版本)
steps:
- task: DotNetCoreCLI@2
displayName: 'dotnet pack'
inputs:
command: pack
nobuild: true
includesymbols: true
includesource: true
versioningScheme: byPrereleaseNumber
majorVersion: '$(AssemblyInfo.AssemblyInformationalVersion.Major)'
minorVersion: '$(AssemblyInfo.AssemblyInformationalVersion.Minor)'
patchVersion: '$(AssemblyInfo.AssemblyInformationalVersion.Patch)'
...但我用新生成的 semVer 收到了 409 条回复!! ** 废话!! **
NuGet Push
即可!- task: NuGetCommand@2
displayName: 'NuGet push'
inputs:
command: push
publishVstsFeed: 'b64b1c9a-18fc-4e6f-aae7-3726c813f034'
continueOnError: true
现在,我的
debug
构建配置 CI 管道在预发布模式下构建完整源代码和符号伴随的 NuGet 包,不会使管道失败或在其上放置警告符号。耶
我使用一个单独的几乎相同的 CI 管道来构建“发布”模式并创建“发布”样式 semVer。