Teamcity Agent Requirement Parameter - teamcity

I have a TeamCity project with multiple sub-probjects. How do I get a subproject to run on a specific agent without hard coding it in the agent requirement upfront? I want to do something like..
That way instead of copying the subproject for each agent I can just have one project and specify an agent name at execution time in some config. Using TeamCity 9.

You can create agent pools and assign specific agents to a project. To do this click on the "agents" link at the top .
Basically, you can define that targets of a particular project should only run on particular agent.
EDIT
If you want to define it at runtime, you have to go back to defining an agent requirement in the targets. You set a paremeter for agent name in the first target .In all the subsequent targets, you can create build chains and pass parameters from one target to another. In the definition of the target, you set an agent condition saying agent name matches whatever value you are passing in your custom variable In the first target you can have a prompt/dropdown and you can initialize an agent based run for a complete build chain.
Or you can assign and unassign agents from the projects pools before each run and then run the targets. For ex in agent pool you can set Project A to only build on agent 1 . After the run is complete, you change Project A to run only on target2 .
I will recommend the first option over the second

This plugin may do what you want. You can define a series of different values for the same parameter(s) and it will run across all of them. This could be agent names or environment variables or node.js versions or whatever.
https://github.com/presidentio/teamcity-matrix-build-plugin

Related

How to loop over snapshot dependencies parameters using teamcity REST API

In my CentOS 7 setup , Top level job 'Build A' has snapshot dependencies on other jobs 'Build B' and 'Build C'.
I am currently referring to parameters from those dependent Build B and Build C using '%dep.Build_B.param%' and '%dep.Build_C.param%' hardcoded in build step in top-level 'Build-A' job.
However list of dependent jobs may change forcing me to change hardcoded dependent job/build name params.
Is there any Teamcity REST API where i can get list of Jobs that are dependent on current Job?
So that i can loop over their build ids and construct '%dep' param name dynamically.
Answer was not found by googling.
If you want to find dependencies for your Build Configuration
You could try request the Build Configuration and provide required fields as a query parameters.
In terms of TeamCity Rest API the BuildConfiguration is named "BuildType"
Example:
GET /app/rest/buildTypes/{BUILD_CONFIGURATION_ID}?fields=artifact-dependencies,snapshot-dependencies
BuildType fields documented:
https://www.jetbrains.com/help/teamcity/rest/buildtype.html#Properties
BuildType locator documented:
https://www.jetbrains.com/help/teamcity/rest/buildtypelocator.html
(locator in example is {BUILD_CONFIGURATION_ID})

How to change variable values according to agent?

On Jenkins it is possible to set same arguments per agent but with different values e.g
Mac agent:
JENKINS_REPOS=/Users/johndoe/Repositories
UNITY_VERSIONS_PATH=/Users/johndoe/Editors
Windows agent:
JENKINS_REPOS=C:\Program Files\android\Repositories
UNITY_VERSIONS_PATH=C:\Program Files\android\Editors
once done, I can run the same pipeline on both agents and values change dynamically, according to agent I specify before build starts e.g agent Mac
I saw there is an option to define arguments on agents, however it does not really work except for system.agent.checkoutDir - I can set custom directory for each build.
How can I do it in same way on Teamcity? Thanks in advance.

How to isolate multiple Teamcity agents from getting picked up by a specific job

I would like my build job to not build on specific teamcity agents and there is no common pattern for the build agent names. Is there a way I can isolate multiple agents from getting picked up by a single job.
For example I can make sure that the build job does not pick up 1 agent using the following parameter.
teamcity.agent.name
does not match
agent-001
How can I similarly tell the teamcity job to not run on the following agents as well.
"123-agent"
"my_agent"
"test_agent"
"agent_do_not_use"
I cannot use the same parameter, teamcity.agent.name with does not match for multiple agents.
Can you all teamcity experts help me out here please on what is the best way to achieve this.
You can add agent requirement with "does not match" condition which accepts regular expression and set it to:
123-agent|my_agent|test_agent|agent_do_not_use
Using an agent requirement based on presence (or absence) of a specific property coming from agent's buildAgent.properties file would probably be a better solution to using agent names in the requirement.
Alternative means to manage agent's compatibility are: use agent pools and use agent's Compatible Configurations set to a limited set.
You can add a specific parameter inside the agent configuration on the local machine inside: C:\BuildAgent\conf\buildAgent.properties
Then, you can add something specific like: system.Is<MyFeature>Available=True
Then, in teamcity configuration, you will add an Agent Requirement with this parameter.

Run configuration on specific set of agents?

We're using TeamCity 9 and have a pool of agents, only some of which can run a particular job we've created. It's going to be a while before a new pool can be created with new agents, and in the meantime we would like to set this job to run only on specific ones.
In the configuration settings we can choose system.agent.name, but that only allows us one agent. Is there a way to configure things so that I can run on multiple agents based on their name, so that, say teamcity_agent01, teamcity_agent07 and teamcity_agent12 are eligible?
If the capabilities you want on the agent expose environment variables you can have a command line step refer to the environment variable and that will scope the job to a suitable agent.
e.g.
echo "%env.PATH_TO_GIT%"
You can add environment variables to your agents like this
open file “/conf/buildAgent.properties” at agent
system. This file contains parameters in key=value format.
To add a system properties add line like -> system.os=Linux
To add an environment variable add line like ->
env.JAVA_HOME=/home/java/jdk1.6.0_13 the
The beauty of this is that as you add more capabilities and agents then you don't need to revisit each job to change where it can run
For Teamcity 9.x
Next to the Projects, and Changes select Agents.
Select the agent that you want to run specific jobs on.
Select the "Compatible Configurations" tab.
On the "Current run configuration policy" dropdown select "Run assgined configurations only"
Click on the "+ Assign configuration" button.
Compatible configurations are colored blue. Select as you wish.
The timing of the configurations and when they should run can be configured under each build configuration triggers tab.

How to enqueue more than one build of the same configuration?

We are using two teamcity servers (one for builds and one for GUI tests). The gui tests are triggered from http GET in the last step of the build. (as in http://confluence.jetbrains.com/display/TCD65/Accessing+Server+by+HTTP)
The problem is, that there is only one configuration of the same kind in the queue at the same time. Is there a way to enable multiple starts of the same configuration? Can I use some workaround like sending a dummy id?
At the bottom the section "Triggering a Custom Build" here: http://confluence.jetbrains.com/display/TCD65/Accessing+Server+by+HTTP, you can find information about passing custom parameters to the build.
Just define some unused configuration parameter, like "BuildId", and pass, for example, current date (guid will work as well) to it
...&buildId=12/12/23 12:12:12

Resources