Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I Setup an Agent Requirement in TeamCity that detects if an Application is installed?

I have a build environment with multiple agents.
I would like to set up an Agent Requirement in my build that detects if certain software is installed. In some cases I can look in the env.Path for a particular string. But some software doesn't modify the Path.

I realize that after I install the software i could edit the BuildAgent.properties file to set a particular property, but I'd like it to be more automatic.

The specific instance is I have a build that uses MSDeploy to deploy websites, but it won't work if MSDeploy isn't installed. How can I specify in my build that I need an Agent that has MSDeploy installed?

like image 390
Jeff Martin Avatar asked May 29 '14 17:05

Jeff Martin


People also ask

How do I set up an agent on TeamCity?

A build agent can be configured by adjusting in the <TeamCity Agent Home>/conf/buildAgent. properties file.

How do I add an agent to TeamCity pool?

To be able to add/remove pools and set maximum number of agents in the pool, you need to have the "Manage agent pools" permission granted to the System Administrator and Agent Manager roles in the default TeamCity per-project authorization mode.


2 Answers

You can build a simple agent plugin. Here are a few suggestions:

  • Extend AgentLifeCycleAdapter and implement agentInitialized method
  • Implement logic of detection the necessary application (for example based on some file existence) inside agentInitialized method
  • Use agent.getConfiguration().addConfigurationParameter() to report agent parameter to the server

If your detection logic can be implemented through file detection, you can use FileWatcher to monitor specific files and report parameters based on them even without restart of the agent

like image 191
Oleg Rybak Avatar answered Nov 02 '22 01:11

Oleg Rybak


To my knowledge Agent Requirements work simply by validating either the existence of, or the value set in an Agent Parameter. As you say, this requires editing the <agent home>/conf/buildAgent.properties configuration file, either manually or in some automated way.

In terms of automation, you could take the approach of authoring a build configuration that acts as an agent bootstrapper; i.e. a build that runs on all agents (scheduled overnight / manually triggered) and maintains build agent parameters in the <agent home>/conf/buildAgent.properties file depending on certain conditions on the agent. Something like (pseudo):

if [ exists /path/to/MSDeploy ] then echo MSDeployExists to buildAgent.properties

This comes with a big disclaimer; I haven't tried this myself, and I believe that the agent will restart automatically based on changes to this file, so there may be issues with editing that file automatically. But it's a potential solution to maintaining your requirements in a centralised manner, and if it works then great. I use a similar approach to bootstrapping custom build scripts out to all agents to augment the already rich feature set in TeamCity.

like image 23
SteveChapman Avatar answered Nov 02 '22 01:11

SteveChapman