[英]Ignore duplicates when pushing nuget package to nuget.org from VSTS
I got a build in VSTS that are triggered on every commit in the repository.我在 VSTS 中构建了一个在存储库中的每次提交时都会触发的构建。 Everything works great with one exception.
除了一个例外,一切都很好。
We do not release a new version of the nuget package on every commit.我们不会在每次提交时发布新版本的 nuget 包。 So our nuget push build step fails with http status code 409. I've configured that step so that it can continue anyway.
所以我们的 nuget push 构建步骤失败,http 状态代码为 409。我已经配置了该步骤,以便它可以继续。
Due to the error the build is just "partially successful".由于错误,构建只是“部分成功”。 I'm using the a build badge which also states the same (without context).
我正在使用构建徽章,它也说明了相同的内容(没有上下文)。
How can I tell VSTS to ignore 409 or just replace the existing package (on nuget.org)?如何告诉 VSTS 忽略 409 或仅替换现有包(在 nuget.org 上)?
You can't ignore 409 error in VSTS build and can't replace the existing package in server.您不能忽略 VSTS 构建中的 409 错误,也不能替换服务器中的现有包。
I recommend that you can push the package in the release and fail the release if package is existing.我建议您可以在发布中推送包,如果包存在,则发布失败。
Another way is that, you can check the package in server before push package (eg PowerShell, REST API) during the build and set the condition for push package task (Custom Condition).另一种方式是,您可以在构建过程中在推送包之前检查服务器中的包(例如PowerShell,REST API)并设置推送包任务的条件(自定义条件)。
For example:例如:
Update:更新:
Allow duplicates to be skipped is supported in NuGet Push Task now!现在 NuGet 推送任务支持允许跳过重复项! (Just check Allow duplicates to be skipped option in NuGet Push task.
(只需在 NuGet 推送任务中选中允许跳过重复项选项。
Use -skipDuplicate
flag (available since NuGet 5.1):使用
-skipDuplicate
标志(从 NuGet 5.1 开始可用):
(5.1+) If a package and version already exists, skip it and continue with the next package in the push, if any.
(5.1+) 如果包和版本已经存在,跳过它并继续推送中的下一个包(如果有)。
Source: https://docs.microsoft.com/en-us/nuget/reference/cli-reference/cli-ref-push#options来源: https : //docs.microsoft.com/en-us/nuget/reference/cli-reference/cli-ref-push#options
We had the same problem with duplicated packages on Azure Pipelines.我们在 Azure Pipelines 上遇到重复包的问题。
Solution proposed by starian chen-MSFT is cool but it requires some scripting. starian chen-MSFT 提出的解决方案很酷,但它需要一些脚本。
We came to solution which requires less efforts.我们找到了需要更少努力的解决方案。 You can create command line step and invoke dotnet nuget push with the following parameters:
您可以创建命令行步骤并使用以下参数调用 dotnet nuget push:
dotnet nuget push $(Build.ArtifactStagingDirectory)/*.nupkg --skip-duplicate --api-key $(Config.NuGetApiKey) --source https://api.nuget.org/v3/index.json
The key is parameter --skip-duplicate which just skips the packages if they already exist.关键是参数 --skip-duplicate 如果它们已经存在,它只会跳过包。
In variable $(Config.NuGetApiKey) define your API key for NuGet.org.在变量 $(Config.NuGetApiKey) 中定义 NuGet.org 的 API 密钥。 You should make it secret variable, so that it does not appear anywhere in the logs.
你应该让它成为秘密变量,这样它就不会出现在日志中的任何地方。
Here is the YAML for this command:这是此命令的 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'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.