Default value for checkbox parameter in TeamCity

I am building a nuget in TeamCity and would like to add the "-pre" suffix to the version number when the build is run with checkin. And when the build is manually started, I would like to be able to check the box if this build should be a preview release or a product.

I have a config parameter created like this:

Prerelease configuration parameter

-Pre is always added

In this case, I always add -pre

to the version number, even if I start the build manually and don't check the box.

If I remove the value -pre

from the default for the parameter, then the checkbox suggestion works as expected. But when my build is started with registration, the system doesn't give me a suffix -pre

and I get a production release that only needs to be manually generated.

Any way to implement what I need?

Alternatively, I only want to publish nugets in a manual build trigger and don't care about pre-releases, but I can't find a way to check if the build was started manually or through on check-in.

+3


source to share


2 answers


The first part is relatively simple, using a step to check the value of a checkbox and set a parameter based on it. I used powershell here, but it can be done in bash (I assumed powershell is how you create nuget packages)

Please note that I changed your logic a bit, but it gives the desired result.

  • Define two variables

Variables

  1. Check the box

Checkbox definition

  1. Setting up two build steps

Build Steps

  1. In the first step, check the parameter and use it to set another parameter

First Step

  1. In the second step, I will prove that the value was set correctly


enter image description here

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

As for your second requirement, I'll again make the assumption that you want to publish the nuget package based on its Release build, not the pre-release build (if I assumed this would incorrectly tell me)

Conditional build steps based on parameter value is something I've been tracking for a while on YouTrack. This has been requested since 2011 but still hasn't included it as a feature. I made this comment in 2014 as a job, but I have no Java skills (you could) - My comment on YouTrack issue

There is an alternative way to get this to work, which may require some rebuilding of your build configurations.

If your Publish NuGet step is not triggered by anything (if you run it with a previous build), you can create a build step that

  • Checks parameter% ReleaseSuffix%
  • Allows REST APIs to trigger build for NuGet publishing

It potentially looks something like this: just make sure you replace the highlighted bits

Trigger Build

TeamCity Documentation

Hope it helps

+4


source


While the accepted answer here is very good, it has a flaw; you will not be able to use the build function of the information collector as it runs before the first step. If you don't want to merge your assemblies together, install the version in the first and use it in the second (yuck).

I was able to find a solution that should give you the same results by going through the options, setting them like this:

Configuration options



PrereleaseLabel

The reason for using the "EmptyString" parameter is that without it, the default is "true".

I've tested this with manual triggers (release and preview) and VCS triggers (preview only), all functioning as expected in TeamCity v9.0.3 (build 32334).

+1


source







All Articles