The plugin provides support for developing TeamCity plugins, creating agent and server side archives, publishing them to plugins portal, downloading and installing a TeamCity server and tasks to deploy, start and stop the server and agent.
To build the plugin and run the unit tests run
./gradlew -s check
To run the functional tests run
./gradlew -s functionalTest
To test the samples run
./gradlew -s samplesTest
The plugin archive published to the Gradle Plugin Portal contains five plugins:
-
io.github.rodm.teamcity-base
- Allows extension propertiesversion
,allowSnapshotVersions
,validateBeanDefinition
, anddefaultRepositories
to be set and shared to subprojects applying the other plugins. -
io.github.rodm.teamcity-server
- Provides tasks to package, sign and publish a TeamCity plugin. -
io.github.rodm.teamcity-agent
- Provides tasks to package the Agent-side of a TeamCity plugin. -
io.github.rodm.teamcity-common
- Adds thecommon-api
dependency to a project to build a library used by both the agent-side and server-side plugin components. -
io.github.rodm.teamcity-environments
- Adds tasks to download and install a TeamCity Server, to deploy and un-deploy plugins to the server, and to start and stop a TeamCity Server and Build Agent.
Refer to the Gradle Plugin Portal for instructions on how to apply the server, agent, common, base and environments plugins.
The plugins add the following configurations.
-
provided
: Theprovided
configuration is used to define dependencies required at compile time but not to be included in the plugin. By default, the plugins add theagent-api
andserver-api
dependencies when thejava
plugin is also applied. -
agent
: Theagent
configuration is used to define additional dependencies to be included in the agent plugin lib directory when used with the agent plugin. When used with the server plugin the dependencies are added to the agent directory of the plugin archive. -
server
: Theserver
configuration is used to define additional dependencies to be included in the server plugin lib directory when used with the server plugin. -
plugin
: Theplugin
configuration is used by the agent and server plugins to publish the agent and server plugin archives.
The following properties are defined in the teamcity
configuration block. The version property controls the version
of the TeamCity API dependencies added to the provided
configuration.
-
version
: The version of the TeamCity API to build against. Default is '9.0'. -
allowSnapshotVersions
: Allow a snapshot version to be specified in theversion
property. Default is false. -
validateBeanDefinition
: The validation mode used to validate plugin bean definition files. Default iswarn
. Set toignore
to suppress warnings. Set towarn
to log all warnings. Set tofail
to log all warnings and fail the build if there are any. -
defaultRepositories
: The defaultRepositories flag controls adding the default repositories to the build. By default, Maven Central and the TeamCity repository, https://download.jetbrains.com/teamcity-repository, are configured for resolving dependencies. Setting this flag to false allows a local repository to be used for resolving dependencies.
Applying the base plugin allows the extension properties version
, allowSnapshotVersions
, validateBeanDefinition
and defaultRepositories
to be inherited by sub-projects applying the other plugins.
Plugin descriptor defined in the build script.
teamcity {
version = '2021.2-SNAPSHOT'
allowSnapshotVersions = true // allow snapshot versions
validateBeanDefinition = "fail" // fail build on any plugin validation errors
defaultRepositories = true // use default repositories to resolve dependencies
}
The plugin when applied with the Java Plugin, adds the JetBrains Maven repository and adds the TeamCity server-api
,
server-web-api
and tests-support
dependencies to the provided
and testImplementation
configurations. If the
Java Plugin is not applied the plugin provides only the tasks to package and publish the server side plugin archive
if a plugin descriptor is defined.
The server plugin can be combined with the agent plugin in the same project but not with the Java Plugin.
The following properties can be defined in the server
configuration block.
-
descriptor
: The plugin descriptor, the descriptor can be defined within the build script or reference an external file. -
tokens
: The tokens property is a map of tokens to be replaced in the descriptor file with values. This only applies if the descriptor is referencing an external file. -
files
: The files property is a CopySpec that defines additional files to be included in the plugin archive. -
web
: The web property is a ConfigurableFileCollection that defines additional files to be included in thebuildServerResources
folder in the plugin jar file. For example this property supports adding files generated bywebpack
to build a plugin using the Sakura UI. -
archiveName
: The archiveName property defines the name of the plugin archive output by theserverPlugin
task. Defaults to the name of the project and the project version.
The plugin descriptor properties shown in the examples below and described in the TeamCity documentation for Server-Side Plugin Descriptor
-
serverPlugin
: Builds and packages a TeamCity plugin. The task performs validation of the plugin descriptor and outputs a warning if a required value is missing. The plugin zip file is output to the directorybuild/distributions
. -
signPlugin
: Signs a plugin before publishing to the JetBrains TeamCity Plugin Repository -
publishPlugin
: Publishes a plugin to the JetBrains TeamCity Plugin Repository -
generateDescriptor
: If the descriptor is defined in the build script this task is enabled and will output the descriptor to the build directory. -
processDescriptor
: If the descriptor is defined as an external file this task is enabled and will copy the file to the build directory. (build/descriptor/server
)
The plugin enhances the jar
task to perform validation of the bean definition file and outputs a warning if
there are no beans defined or if a class is missing from the jar file.
Plugin descriptor defined in the build script.
teamcity {
// Use TeamCity 2018.1 API
version = '2018.1'
// Plugin descriptor
server {
descriptor {
// required properties
name = project.name
displayName = 'TeamCity Plugin'
version = project.version
vendorName = 'vendor name'
// optional properties
description = 'Example TeamCity plugin'
downloadUrl = 'download url'
email = '[email protected]'
vendorUrl = 'vendor url'
vendorLogo = 'vendor logo'
// deployment properties
useSeparateClassloader = true
allowRuntimeReload = true
nodeResponsibilitiesAware = true
// requirements properties
minimumBuild = '58245' // 2018.1
maximumBuild = '78938' // 2020.1.5
parameters {
parameter 'name1', 'value1'
parameter 'name2', 'value2'
}
dependencies {
plugin 'plugin1-name'
plugin 'plugin2-name'
tool 'tool1-name'
tool 'tool2-name'
}
}
web {
webpack // A task the runs webpack
// or
project.files("${buildDir}/frontend") // the contents of a directory
}
// Additional files can be included in the server plugin archive using the files configuration block
files {
into('tooldir') {
from('tooldir')
}
}
}
}
The build numbers for the properties minimumBuild
and maximumBuild
can be found on the
previous releases page.
Plugin descriptor defined in an external file at the root of the project. A map of tokens to be replaced in the
descriptor file can be provided using the tokens
property.
teamcity {
// Use TeamCity 2018.1 API
version = '2018.1'
server {
// Locate the plugin descriptor in the root directory of the project
descriptor = file('teamcity-plugin.xml')
tokens = [VERSION: project.version, VENDOR_NAME: 'vendor name']
}
}
The following example uses the Kotlin DSL.
teamcity {
version = "2018.1"
server {
descriptor {
// required properties
name = project.name
displayName = "TeamCity Plugin"
version = project.version as String?
vendorName = "vendor name"
// optional properties
description = "Example TeamCity plugin"
downloadUrl = "download url"
email = "[email protected]"
vendorUrl = "vendor url"
vendorLogo = "vendor logo"
// deployment properties
useSeparateClassloader = true
allowRuntimeReload = true
nodeResponsibilitiesAware = true
// requirements properties
minimumBuild = "58245" // 2018.1
maximumBuild = "78938" // 2020.1.5
parameters {
parameter("name1", "value1")
parameter("name2", "value2")
}
dependencies {
plugin("plugin1-name")
plugin("plugin2-name")
tool("tool1-name")
tool("tool2-name")
}
}
web {
tasks.named("webpack") // A task the runs webpack
// or
project.files("${buildDir}/frontend") // the contents of a directory
}
files {
into("tooldir") {
from("tooldir")
}
}
}
}
The signPlugin
task is used to sign the plugin archive before publishing to the
JetBrains TeamCity Plugin Repository.
teamcity {
server {
descriptor {
...
}
sign {
certificateFile = findProperty('ca.crt')
privateKeyFile = findProperty('private-key.file')
password = findProperty('private-key.password')
}
}
}
The publishPlugin
task is used to upload the plugin archive to the
JetBrains TeamCity Plugin Repository. Before publishing a plugin you will need
to create a JetBrains Account, follow the 'Sign In' link at the top of the plugin repository page.
The publishPlugin
task cannot be used to publish new plugins, the first upload must be completed using the
Upload plugin link on the plugin repository website.
The publishPlugin
task requires a JetBrains Hub token to publish a plugin to the
repository as shown in the following examples.
The following example configures the publishPlugin
task.
publishPlugin {
token = findProperty('jetbrains.token')
}
The following example uses the Kotlin DSL.
tasks.withType<PublishPlugin> {
token = findProperty("jetbrains.token") as String?
}
The token and other properties can also be configured in the publish
section of the server
configuration as
shown in the following example. Optionally one or more channels can be specified using the channels
property,
by default the plugin is published to the 'Stable' channel. An optional notes
property can be set to describe the
changes made to the version of the plugin to be uploaded. The change or update notes text is shown on the plugin
repository next to each plugin version.
teamcity {
server {
descriptor {
...
}
publish {
channels = ['Beta']
token = findProperty('jetbrains.token')
notes = 'change notes'
}
}
}
It is recommended to store the credentials for the JetBrains Plugin Repository in $HOME/.gradle/gradle.properties
.
The plugin when applied with the Java Plugin, adds the JetBrains Maven repository and adds the TeamCity agent-api
and
tests-support
dependencies to the provided
and testImplementation
configurations. If the Java Plugin is not
applied the plugin provides only the tasks to package the agent side plugin archive if a plugin descriptor is defined.
The following properties can be defined in the agent
configuration block.
-
descriptor
: The plugin descriptor, the descriptor can be defined within the build script or reference an external file. -
tokens
: The tokens property is a map of tokens to be replaced in the descriptor file with values. This only applies if the descriptor is referencing an external file. -
files
: The files property is a CopySpec that defines additional files to be included in the plugin archive. -
archiveName
: The archiveName property defines the name of the plugin archive output by theagentPlugin
task. Defaults to the name of the project, if theteamcity-agent
plugin andteamcity-server
plugin are applied to the same project the agent plugin archive is appended with '-agent' and the project version.
The plugin descriptor properties are shown in the examples below and described in the TeamCity documentation for Agent-Side Plugin Descriptor
-
agentPlugin
: Builds and packages the agent side of a TeamCity plugin. The artifacts defined on the 'agent' configuration are added to the lib directory of the agent plugin archive. The task performs validation of the plugin descriptor and outputs a warning if a required value is missing. -
generateAgentDescriptor
: If the descriptor is defined in the build script this task is enabled and will output the descriptor to the build directory. -
processAgentDescriptor
: If the descriptor is defined as an external file this task will copy the file to the build directory. ('build/descriptor/agent')
The plugin enhances the jar
task to perform validation of the bean definition file and outputs a warning if
there are no beans defined or if a class is missing from the jar file.
Agent side plugin descriptor
teamcity {
version = teamcityVersion
agent {
descriptor {
pluginDeployment {
useSeparateClassloader = false
executableFiles {
include 'file1'
include 'file2'
}
}
dependencies {
plugin 'plugin-name'
tool 'tool-name'
}
}
}
}
Agent tool descriptor
teamcity {
version = teamcityVersion
agent {
descriptor {
toolDeployment {
executableFiles {
include 'tooldir/file1'
include 'tooldir/file2'
}
}
dependencies {
plugin 'plugin-name'
tool 'tool-name'
}
}
// Additional files can be included in the agent plugin archive using the files configuration block
files {
into('tooldir') {
from('tooldir')
}
}
}
}
The following example uses the Kotlin DSL.
val teamcityVersion by extra((findProperty("teamcity.api.version") ?: "2018.1") as String)
teamcity {
version = teamcityVersion
agent {
descriptor {
pluginDeployment {
useSeparateClassloader = false
executableFiles {
include("file1")
include("file2")
}
}
dependencies {
plugin("plugin-name")
tool("tool-name")
}
}
files {
into("tooldir") {
from("tooldir")
}
}
}
}
Applying this plugin provides tasks to download, install, start and stop a local TeamCity Server and Build Agent or start and stop a server or agent using Docker. This allows a plugin to be debugged or tested against multiple versions of TeamCity.
The environments plugin supports two different types of environment a local environment and a Docker environment.
The types of environments supported are implemented using Gradle’s ExtensiblePolymorphicDomainObjectContainer
that
can be extended to support other environment types. An example plugin that extends the environments plugin to
support running multiple nodes can be found in the following project teamcity-docker-multi-node.
The environments
configuration is available by applying the com.github.rodm.teamcity-environments
plugin.
The following properties can be defined in the environments
configuration block
and are only used by local TeamCity environments.
-
downloadsDir
: The directory the TeamCity installers are downloaded to. Defaults todownloads
-
baseDownloadUrl
: The base URL used to download the TeamCity installer. Defaults tohttps://download.jetbrains.com/teamcity
. -
baseHomeDir
: The base directory for a TeamCity install. Defaults toservers
. -
baseDataDir
: The base directory for a TeamCity Data directory. Defaults todata
.
The following Gradle properties can be used to override the shared environment properties from the command line or by setting a value in a gradle.properties file.
-
teamcity.environments.downloadsDir
-
teamcity.environments.baseDownloadUrl
-
teamcity.environments.baseDataDir
-
teamcity.environments.baseHomeDir
The environments
configuration block supports defining multiple TeamCity environments.
When creating an environment the default is to create or register a local TeamCity environment.
To configure a local TeamCity environment the configuration block supports the following properties
-
version
: The TeamCity version, the version of TeamCity to download and install locally. Defaults to '9.0'. -
downloadUrl
: The URL used to download the TeamCity installer. Defaults to${baseDownloadUrl}/TeamCity-${version}.tar.gz
. -
homeDir
: The path to a TeamCity install. Defaults to${baseHomeDir}/TeamCity-${version}
-
dataDir
: The path to the TeamCity Data directory. Defaults to${baseDataDir}/${version}
, version excludes the bug fix digit. -
javaHome
: The path to the version of Java used to run the server and build agent. Defaults to the Java used to run Gradle. -
serverOptions
: Options passed to the TeamCity server via theTEAMCITY_SERVER_OPTS
environment variable. Default-Dteamcity.development.mode=true
,-Dteamcity.development.shadowCopyClasses=true
,-Dteamcity.superUser.token.saveToFile=true
,-Dteamcity.kotlinConfigsDsl.generateDslDocs=false
these plugin development settings are described on the Development Environment page. -
agentOptions
: Options passed to the TeamCity agent via theTEAMCITY_AGENT_OPTS
environment variable. -
plugins
: The collection of plugins to be deployed to the TeamCity server for this environment. Defaults to the plugin output by theserverPlugin
task when thecom.github.rodm.teamcity-server
plugin is also applied.
The following Gradle properties can be used to override the properties for a specific environment from
the command line or by setting a value in a gradle.properties file. Replace <environment>
with the name
defined in the build script.
-
teamcity.environments.<environment>.downloadUrl
-
teamcity.environments.<environment>.homeDir
-
teamcity.environments.<environment>.dataDir
-
teamcity.environments.<environment>.javaHome
-
teamcity.environments.<environment>.serverOptions
-
teamcity.environments.<environment>.agentOptions
The following Gradle property teamcity.environments.shutdownTimeout
is used to set the seconds the Stop Server
task will wait for the TeamCity Server to stop. This property is only used by the Stop Server task for local
TeamCity environments. The default value is 10 seconds.
For each environment the following tasks are created based on the environment name:
-
deployTo<environment>
: Deploys one or more plugin archives to the TeamCity server for the environment, requires the environmentdataDir
property. If the environment is using TeamCity version 2018.2 or later and the server is running, the deploy task will send unload and load requests to the server. This allows changes to be made to the plugin without having to restart the server. Note that this feature currently relies on the file name of the plugin not changing between deploys. -
undeployFrom<environment>
: Un-deploys one or more plugin archives from the TeamCity server for the environment, requires the environmentdataDir
property. -
start<environment>Sever
: Starts the TeamCity Server for the environment, requires the environmenthomeDir
anddataDir
properties to be defined. -
stop<environment>Server
: Stops the TeamCity Server for the environment, requires the environmenthomeDir
property to be defined. -
start<environment>Agent
: Starts the default TeamCity Build Agent for the environment, requires the environmenthomeDir
property to be defined. -
stop<environment>Agent
: Stops the default TeamCity Build Agent for the environment, requires the environmenthomeDir
property to be defined. -
start<environment>
: Starts both the TeamCity Server and Build Agent for this environment. -
stop<environment>
: Stops both the TeamCity Server and Build Agent for this environment. -
download<environment>
: Downloads a TeamCity installer for the environment, this task uses thedownloadBaseUrl
and the environmentversion
andhomeDir
properties. -
install<environment>
: Installs TeamCity for the environment, this tasks uses thedownloadBaseUrl
and the environmenthomeDir
properties.
teamcity {
// Use TeamCity 2018.1 API
version = '2018.1'
server {
// Locate the plugin descriptor in the root directory of the project
descriptor = file('teamcity-plugin.xml')
}
environments {
// use a local web server for downloading TeamCity distributions
baseDownloadUrl = "http://repository/"
// store the downloaded TeamCity distributions in /tmp
downloadsDir = '/tmp'
// base properties for TeamCity servers and data directories
baseHomeDir = 'teamcity/servers'
baseDataDir = 'teamcity/data'
teamcity91 {
version = '9.1.7'
javaHome = file('/opt/jdk1.7.0_80')
// Add to the default server options
serverOptions '-Dproperty=value'
serverOptions '-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5500'
}
teamcity20172 {
version = '2017.2.4'
downloadUrl = 'http://repository/teamcity/TeamCity-2017.2.4.tar.gz'
homeDir = file("$rootDir/teamcity/servers/TeamCity-2017.2.4")
dataDir = file("$rootDir/teamcity/data/2017.2")
javaHome = file('/opt/jdk1.8.0_202')
// Replace the default server options
serverOptions = '-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5500'
}
'teamcity2018.2' {
version = '2018.2.2'
javaHome = file('/opt/jdk1.8.0_202')
}
// explicitly specifying the environment type
'teamcity2022.04'(LocalTeamCityEnvironment) {
version = '2022.04.3'
}
}
}
The following example shows environments being configured using the Kotlin DSL.
val downloadsDir by extra((project.findProperty("downloads.dir") ?: "${rootDir}/downloads") as String)
val java7Home by extra((project.findProperty("java7.home") ?: "/opt/jdk1.7.0_80") as String)
val java8Home by extra((project.findProperty("java8.home") ?: "/opt/jdk1.8.0_202") as String)
teamcity {
version = "2018.1"
server {
descriptor = file("teamcity-plugin.xml")
}
environments {
baseDownloadUrl = "http://repository/"
downloadsDir = extra["downloadsDir"] as String
baseHomeDir = "teamcity/servers"
baseDataDir = "${rootDir}/data"
create("teamcity9") {
version = "9.1.7"
javaHome = java7Home
// Add to the default server options
serverOptions("-Dproperty=value")
serverOptions("-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5500")
}
register("teamcity2017.2") {
version = "2017.2.4"
javaHome = java8Home
// Replace the default server options
setServerOptions("-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5500")
}
register("teamcity2020.2") {
version = "2020.2.4"
}
// explicitly specifying the environment type
register("teamcity2022.04", LocalTeamCityEnvironment::class.java) {
version = '2022.04.3'
}
}
}
To create an environment that uses Docker to start and stop a TeamCity Server and Build Agent an environment can specify the type when creating or registering the environment.
The following example shows the different ways Docker environments can be configured using the Groovy DSL.
teamcity {
environments {
'teamcity2021.1'(DockerTeamCityEnvironment) {
version = '2021.1.4'
}
create('teamcity2021.2', DockerTeamCityEnvironment) {
version = '2021.2.3'
}
register('teamcity2022.04', DockerTeamCityEnvironment) {
version = '2022.04'
}
}
}
The following example shows the different ways Docker environments can be configured using the Kotlin DSL.
teamcity {
environments {
create('teamcity2021.2', DockerTeamCityEnvironment::class.java) {
version = '2021.2.3'
}
register("teamcity2022.04", DockerTeamCityEnvironment::class.java) {
version = '2021.2.3'
}
}
}
To configure a Docker TeamCity environment the configuration block supports the following properties
-
version
: The TeamCity version, the version of TeamCity to download and install locally. Defaults to '9.0'. -
dataDir
: The path to the TeamCity Data directory. Defaults to${baseDataDir}/${version}
, version excludes the bug fix digit. -
serverImage
: The name of the Docker image to use for the TeamCity Server. Defaults tojetbrains/teamcity-server:${version}
. -
serverTag
: The tag of the Docker image to use for the TeamCity Server. Defaults to the environmentversion
. -
serverName
: The name of the running Docker container for the TeamCity Server. Defaults toteamcity-server
. -
agentImage
: The name of the Docker image to use for the TeamCity Build Agent. Defaults tojetbrains/teamcity-agent:${version}
.. -
agentTag
: The tag of the Docker image to use for the TeamCity Build Agent. Defaults to the environmentversion
. -
agentName
: The name to the running Docker container for the TeamCity Build Agent. Defaults toteamcity-agent
. -
serverOptions
: Options passed to the TeamCity server via theTEAMCITY_SERVER_OPTS
environment variable. Default-Dteamcity.development.mode=true
,-Dteamcity.development.shadowCopyClasses=true
,-Dteamcity.superUser.token.saveToFile=true
,-Dteamcity.kotlinConfigsDsl.generateDslDocs=false
these plugin development settings are described on the Development Environment page. -
agentOptions
: Options passed to the TeamCity agent via theTEAMCITY_AGENT_OPTS
environment variable. -
plugins
: The collection of plugins to be deployed to the TeamCity server for this environment. Defaults to the plugin output by theserverPlugin
task when thecom.github.rodm.teamcity-server
plugin is also applied.
For each environment the following tasks are created based on the environment name:
-
deployTo<environment>
: Deploys one or more plugin archives to the TeamCity server for the environment. If the environment is using TeamCity version 2018.2 or later and the server is running, the deploy task will send unload and load requests to the server. This allows changes to be made to the plugin without having to restart the server. Note that this feature currently relies on the file name of the plugin not changing between deploys. -
undeployFrom<environment>
: Un-deploys one or more plugin archives from the TeamCity server for the environment. -
start<environment>Sever
: Starts the TeamCity Server for the environment. -
stop<environment>Server
: Stops the TeamCity Server for the environment. -
start<environment>Agent
: Starts the TeamCity Build Agent for the environment. -
stop<environment>Agent
: Stops the TeamCity Build Agent for the environment. -
start<environment>
: Starts both the TeamCity Server and Build Agent for this environment. -
stop<environment>
: Stops both the TeamCity Server and Build Agent for this environment.
To start and stop a TeamCity Server and Build Agent using Docker requires {uri-docker-desktop}[Docker] to be installed and running before executing the environment tasks.
teamcity {
version = "2018.1"
environments {
'teamcity2022.04'(DockerTeamCityEnvironment) {
version = '2022.04.3'
port = '7111'
serverImage = 'my-teamcity-server'
serverName = 'my-server'
agentImage = 'my-teamcity-agent'
agentName = 'my-agent'
// Add to the default server and agent options
serverOptions '-Dproperty=value'
serverOptions '-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5500'
agentOptions '-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5501'
}
}
}
The samples directory contains a number of projects using the plugin.
The following projects use the plugin.