The use of plugins allows you to extend the TeamCity functionality. See the existing TeamCity plugins written by JetBrains developers and community.
This document provides information on how to develop and publish a server-side plugin for TeamCity using Maven. The plugin will display the Hello World jsp page when using a specific URL to the TeamCity Web UI.
A plugin in TeamCity is a zip archive containing a number of classes packed into a JAR file.
Set up the environment
To get started writing a plugin for TeamCity, set up the plugin development environment.
- Download and install TeamCity on your development machine. Since you are going to use this machine to test your plugin, it is recommended that this TeamCity server is of the same version as your production server. We are using TeamCity 9.0.2 installed on Windows 8 Pro in our setup.
- Download and install a Java IDE; we are using Intellij IDEA 14.0.3 Community Edition, which has a built-in Maven integration.
- Download and install Oracle Java. Set Java_Home on your system. We are using Java 1.7.0_25.
- Download and install Apache Maven. Set M2_HOME. Run
mvn -versionto verify your setup. We are using Maven 3.2.5. in our setup.
Generate a Maven project
We'll generate a Maven project from an archetype residing in JetBrains Maven repository; executing the following command will produce a project for a server-side-only plugin depending on 9.0 TeamCity version:
You will be asked to enter the Maven
packaging for your plugin. The
artifactId will be used as the internal name of your plugin.
We are using the following settings:
When the build finishes, you'll see that the
demo-plugin directory (the same name as the
artifactId) was created in the home directory of the current user.
The root of the
demo-plugin directory contains the following:
readme.txtfile with minimal instructions to develop a server-side plugin
pom.xmlfile which is your Project Object Model
teamcity-plugin.xmlfile which is your plugin descriptor containing meta information about the plugin.
demo-plugin-serverdirectory contains the plugin sources:
\src\main\java\pomcontains the App.Java file
src\main\resourcescontains the plugin resources.
src\main\resources\META-INFfolder contains Spring bean definition files. TeamCity plugins are initialized in their own Spring containers and every plugin needs a Spring bean definition file describing the main services of the plugin. The
build-server-plugin-demo-plugin.xmlis a bean definition file for our plugin.
builddirectory contains the xml files which define how the project output is aggregated into a single distributable archive.
Describe your plugin
teamcity-plugin.xml file in the project root folder and add the plugin display name and description by modifying the corresponding
attributes in the file. You can also specify additional information, such as the plugin author, email and etc.
Modify the project sources
pom.xml from the project root folder with Intellij IDEA.
We are going to make a controller class which will return
Hello.jsp via a specific TeamCity URL.
Create the plugin web-resources
The plugin web resources (files that are accessed via hyperlinks and JSP pages) are to be placed into the
buildServerResources subfolder of the plugin's resources:
- First we'll create the directory for our jsp: go to the
src\main\resourcesdirectory in IDEA, right-click the folder, select New -> Directory and create the
- Next go to the
src\main\resources\buildServerResources, right-click the folder, select New -> File and create the
Create the controller
\src\main\java\pom and open AppServer.Java to create a custom controller:
- We'll create a simple controller which extends the TeamCity
class and implements
- The TeamCity open API provides the
jetbrains.buildServer.web.openapi.WebControllerManager which allows registering custom controllers using the path to the controller: the path is a part of URL starting with a
/appended to the URL of the server root.
At the moment our AppServer.Java looks as follows:
- билдим проект мавеном
- копируем зип побилженного плагина в <TeamCity data directory>/plugins
- стартуем сервер и убеждаемся что плагин работает