2

In TeamCity, is it possible to parameterize the agent requirements based on project or build configuration parameters? E.g. can value include %...% substitutions?

An example: we have a project parameters env.XXX_VERSION which specifies the needed version of the XXX product in all the build configurations of the project. We can then use this value in the relevant build scripts of the project. (Over time we make copies of this build project for different variants of some of the products we depend on, so we now have 12 different projects with different values for the parameters). Now I also would like to include an agent requirement from all the relevant build configurations in the project so only the usable agents will be considered. But given the number of build configurations and the number of variant projects, I would prefer to parameterize the requirement on the value of the exiting env.XXX_VERSION. Is this possible?

(Today, all our agents includes all possible versions of the software, but will no longer be possible, so we will need requirements on the agents from the projects of build configurations)

Giacomo1968
  • 58,727

3 Answers3

2

It seems like you already know what you want to do and the issue is the large number of agents and configurations that you need to deal with.

Why not automate this using TeamCity's REST API? TeamCity's server has a built in HTTP API that you can use to edit/update (almost) any of the fields you would be able to using the web interface.

You can interact with the API using your preferred scripting language using HTTP GET/PUT calls to get and update values. In this case, I think it would be worth your time to write a script to avoid having to go through the UI to update all the build configurations you mentioned.

You'll write a single script (in whatever scripting language you're comfortable using) that you can run once to set all the agent requirements. Pseudo code following

  1. Iterate over the projects in TeamCity

Get the list of projects

curl -i -H "Accept: application/json" http://teamcity/httpAuth/app/rest/projects --user username:password
  1. Get the XXX_VERSION parameter from the projects.

Loop over all projects, get all parameters and parse our XXX_VERSION

curl http://teamcity/app/rest/projects/id:PROJECT_NAME/parameters
  1. Set the agent requirement on the build configurations.

For each build configuration, in each project, set the agent requirements on the build configuration using the parsed out XX_VERSION value

curl -X PUT http://teamcity/httpAuth/app/rest/buildTypes/<buildTypeLocator>/agent-requirements/<id> --user username:password

This is the general idea but not complete, by spending time getting this script out of the way you'll save a lot of time managing it via TeamCity UI.

https://confluence.jetbrains.com/display/TCD9/REST+API

Giacomo1968
  • 58,727
kdtong
  • 46
  • 3
0

You can force TeamCity to built on a specific agent without disabling all other connected agents.

Here's how:

Goto Build Configuration Settings

Next Agent Requirements

Now you have to set an Explicit Requirement for a particular agent:

Parameter Name: system.agent.name

Condition: equals

Value: YOUR_SPECIFIC_AGENT_NAME

Also you can try this:

Browse through: TeamCity --> Administration --> Agents --> Select an Agent --> Compatible Configurations tab, then Current run configuration policy then Run assigned configurations only and click on + Assign configurations and finish.

Please let me know if this helps.

Thank you.

-1

I could not find a way to parameterize the value with %...% substitutions, but I found a workaround. It's not ideal, but it works for my small use case.

Use case: I am creating build configurations from a template and need each build configuration to only run on a single, specific machine. I wanted to do teamcity.agent.name equals %buildAgentName% in the template to have TeamCity prompt me to fill in the parameter when I create the build configuration from template.

Solution: Instead of using a parameter I just put in a string that would not match any agent names, e.g. teamcity.agent.name equals replaceThisWithActualAgentName in the template. I am not prompted for the parameter but this prevents the build configuration from accidentally running on the wrong machine until I override the agent requirement.

I am not sure if this solves your use case but I am posting it here in case it is helpful for someone else.