问题描述
我在 VSTS 中构建了一个版本,它会在存储库中的每次提交时触发.除了一个例外,一切都很好.
I got a build in VSTS that are triggered on every commit in the repository. Everything works great with one exception.
我们不会在每次提交时发布新版本的 nuget 包.所以我们的 nuget push 构建步骤失败,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 构建中不能忽略 409 错误,也不能替换服务器中的现有包.
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.
这篇关于将 nuget 包从 VSTS 推送到 nuget.org 时忽略重复项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!