5

我正在 TeamCity 中构建 nuget,并希望在签入触发构建时将后缀“-pre”附加到版本号。并且当手动触发构建时,我希望能够提供一个复选框,如果此构建应该是预览版本或生产价值。

我有一个这样创建的配置参数:

预发布配置参数

- 总是添加前

在这种情况下,我总是-pre添加到版本号,即使我手动触发构建并且不选中复选框。

如果我 -pre从参数的默认值中删除该值,则复选框提示符将按预期工作。但是当我的构建是通过签入触发时,系统不会给我-pre后缀,我最终会得到一个只能手动创建的生产版本。

有什么方法可以实现我需要的吗?

或者,我只想在构建的手动触发时发布 nuget,并不真正关心预发布,但我似乎找不到任何方法来检查构建是手动触发还是通过签入触发.

4

2 回答 2

3

第一部分相对简单,使用一个步骤来检查复选框的值并根据它设置一个参数 - 这里我使用了 powershell 但这可以在 bash 中完成(我假设 powershell 因为你正在生产 nuget包)

请注意,我稍微颠倒了您的逻辑,但它会产生您想要的结果。

  1. 定义两个变量

变量

  1. 设置复选框

复选框定义

  1. 设置两个构建步骤

构建步骤

  1. 第一步,测试参数并用它来设置另一个参数

第一步

  1. 在第二步中,我证明该值已正确设置

在此处输入图像描述

You should be able to use %ReleaseSuffix% when you need it.

Regarding your second requirement, I'm again going to make an assumption that you only want to publish a nuget package based on it being a Release build rather than a Pre-Release (if I've assumed this incorrectly let me know)

Conditional build steps based on a parameter value are something I've been tracking for a while now on YouTrack. This has been requested since 2011, but has still not made it in as a feature. I made this comment back in 2014 as a work around, but don't have the Java skills (you might) - My comment on YouTrack Issue

There is an alternative way to get this working, that might require some reworking of your build configurations.

If your "Publish NuGet" step is not triggered by anything (assumming it's triggered by the previous build finishing) then you could have a build step that

  • Checks the %ReleaseSuffix% parameter
  • Calls the REST API to trigger the build to publish the NuGet

It would potentially look something like this - just ensure you replace the highlighted bits

触发构建

TeamCity Documentation

Hope this helps

于 2015-05-17T09:04:36.190 回答
2

Although the accepted answer here is very good, it does have a flaw; you will not be able to use the Assembly Info Patcher build feature, as this executes before the first step. Unless you wish to chain your builds together, setting the version in the first and using that in the second (yuck).

I have managed to find a solution which should give you the same results by tinkering with the parameters, setting them as follows:

配置参数

售前标签

使用“EmptyString”参数的原因是因为没有它,检查值默认为“true”。

我已经使用手动触发器(发布和预发布)和 VCS 触发器(仅限预发布)对此进行了测试,所有这些都在 TeamCity v9.0.3(内部版本 32334)上按预期运行。

于 2015-08-12T11:18:11.920 回答