In this section we will go through the steps to setup both the TeamCity Server and Build Agent in debug mode
and connect a remote debugger to them using IntelliJ IDEA.
To debug the TeamCity Server and Build Agent requires enabling the debug options for each Java process. The following
example shows and environment with debug options for both the server and agent. Note each uses a different port, this
is required if both are to be debugged at the same time.
teamcity {
environments {
teamcity10 {
version = '10.0.4'
javaHome = file(java8Home)
serverOptions '-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005'
agentOptions '-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5006'
}
}
}
Create a Remote Run/Debug Configuration for both the server and the agent, as shown below, the port for each should
match the configuration shown above.
We should then have two Remote Debug configurations as shown below.
Start both the server and agent using the Gradle tasks, 'startTeamcity10Server' and 'startTeamcity10Agent', either
from the command line or using the Gradle Tool Window in IDEA.
We will need a project and a build configuration to test debugging the plugin. Once the server is started create a
project and then a build configuration. The build configuration doesn’t require a VCS root or a build file,
a command line build step using an inline script will do.
Start the Remote debug connection for the server. Open the 'ExampleBuildFeature' class in the main project and
set a breakpoint in the 'describeParameters' method. Using the TeamCity UI edit the build configuration and
add the 'Example Build Feature', the remote debug connection should stop at the breakpoint in the plugin source.
The same can be done for agent-side plugin code, start the Remote debug connection for the agent. Open the
'ExampleBuildFeature' class in the agent sub-project and set a breakpoint in the 'buildStarted' method.
Run the build configuration, the remote debug connection for the agent should stop at the breakpoint in the
agent-side plugin source.
Be aware that the Agent debug connection can become disconnected if the agent preforms an upgrade. This can happen
if the agent-side code is changed and the plugin re-deployed.
This post has hopefully provided some help on testing and debugging TeamCity plugins using the
Gradle TeamCity plugin.