0
votes

Using TeamCity version 2017.2.3 (build 51047).

I have a SMB Upload build step and would like to upload the builds from the default branch to a different location than all other builds.

I seen the following variable that will tell me if its a deafult build %teamcity.build.branch.is_default% however im not too sure how or even if its possible to specify conditional Target URL for the SMB Upload step.

Either with some form on IF block, or ternary statement inline.

Non of this is done using PowerShell. All through the UI, i would prefer to keep it that way if possible. Our old TeamCity install saws essentially just a glorified PowerShell script runner and grew into this un maintainable monolith, besides PowerShell is a rather terrible language.

Essentially what i would like would be builds on any branch going to

//DataStore/builds/my-api-%build.number%.zip

Whilst builds on the default branch go to

//DataStore/builds/default/my-api-%build.number%.zip

Any help would be appreciated thanks.

2

2 Answers

1
votes

In general, this is not possible. The SMB Upload runner doesn't let you specify a condition anywhere in it.

If conditional steps were possible, you could create two steps: Upload from default and Upload from non-default, each with a different Target URL. It turns out that conditional build steps are the most voted-for feature in TeamCity, see this ticket, yet JetBrains are quite opposed to the idea. You may want to vote for the ticket, or at least monitor it.

There is one thing that you can do, other than Powershell. The Target URL field expands variables. (You can tell this by typing a percent sign in the text field: TeamCity immediately starts suggesting variable names. Compare this with the Step name text field above: that has no variable expansion.) Thus, you could enter a Target URL in this form:

//DataStore/builds/%teamcity.build.branch.is_default%/my-api-%build.number%.zip

That way, you'll end up with files being uploaded as

//DataStore/builds/true/my-api-1234.zip
//DataStore/builds/false/my-api-1235.zip

Now that's kind-of ugly. You can improve it in two ways:

1) create symlinks or junctions on your file server (on the directory/filesystem level), so that the above are accessible to the clients as

//DataStore/builds/default/my-api-1234.zip
//DataStore/builds/my-api-1235.zip

2) even better, you can set up a variable that will either contain the value "/default" or "". Then you can change your Target URL to //DataStore/builds%myCleverVariable%/my-api-%build.number%.zip. To do that, you'll need an extra step before this one, a Powershell runner, that will test the value of %teamcity.build.branch.is_default% and set %myCleverVariable% accordingly, using TeamCity service messages.

0
votes

The conditional build step feature has been implemented in TeamCity 2020.1