问题描述
我在 VSTS 中构建了一个在存储库中的每次提交时触发的构建.一切都很好,只有一个例外.
I got a build in VSTS that are triggered on every commit in the repository. Everything works great with one exception.
我们不会在每次提交时发布新版本的 nuget 包.因此,我们的 nuget 推送构建步骤失败并显示 http 状态代码 409.我已经配置了该步骤,以便它可以继续进行.
We do not release a new version of the nuget package on every commit. So our nuget push build step fails with http status code 409. I've configured that step so that it can continue anyway.
由于错误,构建只是部分成功".我正在使用同样声明的构建徽章(没有上下文).
Due to the error the build is just "partially successful". I'm using the a build badge which also states the same (without context).
如何告诉 VSTS 忽略 409 或仅替换现有包(在 nuget.org 上)?
How can I tell VSTS to ignore 409 or just replace the existing package (on nuget.org)?
推荐答案
VSTS build 不能忽略 409 错误,不能替换 server 中已有的包.
You can’t ignore 409 error in VSTS build and can’t replace the existing package in server.
我建议你可以在发布中推送包,如果包存在则发布失败.
I recommend that you can push the package in the release and fail the release if package is existing.
另一种方式是,在构建过程中,您可以在推送包(例如PowerShell,REST API)之前检查服务器中的包,并设置推送包任务的条件(自定义条件).
Another way is that, you can check the package in server before push package (e.g. PowerShell, REST API) during the build and set the condition for push package task (Custom Condition).
例如:
- 添加一个变量来构建定义(例如 hasPackage true)
- 检查包(PowerShell、Rest API 等...)
- 如果包已存在,请将变量设置为 false ("##vso[task.setvariable variable=hasPackage;]false")
- 为推送包任务设置自定义条件(例如 eq(variables['hasPackage'],'false'))
更新:
NuGet 推送任务现在支持跳过重复项!(只需选中 NuGet 推送任务中的 允许跳过重复项 选项.
Allow duplicates to be skipped is supported in NuGet Push Task now! (Just check Allow duplicates to be skipped option in NuGet Push task.
这篇关于从 VSTS 将 nuget 包推送到 nuget.org 时忽略重复项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!