Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Default value for checkbox parameter in TeamCity

I'm building nuget in TeamCity and would like to append suffix "-pre" to version number when build is triggered by a checkin. And when build is triggered manually, I'd like to be able to provide a checkbox if this build should be a preview release or production-worthy.

I've got a Configuration Parameter created like that:

Prerelease configuration parameter

-Pre is always added

In this case I always have -pre added to the version number, even if I trigger the build manually and don't check the checkbox.

If I remove the value -pre from the default value of the parameter, then checkbox prompt works as expected. But when my build is triggered via a check-in, the system does not give me -pre suffix and I end up with a production release which should only be created manually.

Any way to implement what I need?

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

like image 970
trailmax Avatar asked May 15 '15 23:05

trailmax


2 Answers

The first part is relatively easy, using a step to check the value of the checkbox and set a parameter based on it - Here I've used powershell but this could be done in bash (I've assumed powershell as you're producing nuget packages)

Note that I have reversed your logic a bit, but it produces the outcome you desire.

  1. Define two varibles

Variables

  1. Setup the checkbox

Checkbox definition

  1. Setup two build steps

Build Steps

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

First Step

  1. In the second step I'm proving the value has been set correctly

enter image description here

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

Trigger Build

TeamCity Documentation

Hope this helps

like image 56
Evolve Software Ltd Avatar answered Sep 28 '22 13:09

Evolve Software Ltd


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:

Configuration Parameters

PrereleaseLabel

The reason for using the "EmptyString" parameter is because without it, checked value defaults to "true".

I have tested this with manual triggers (release & prerelease) and VCS triggers (prerelease only), all functioning as expected on TeamCity v9.0.3 (build 32334).

like image 35
Rich Clark Avatar answered Sep 28 '22 11:09

Rich Clark