Я бы хотел оспорить принятый ответ обновленным ответом, который был протестирован с TeamCity 9 EAP 4 (сборка 31717) и 8.1.x.простой плагин, который содержит только адаптер событий, такой как:
package com.foo;
import com.intellij.openapi.diagnostic.Logger;
import jetbrains.buildServer.messages.Status;
import jetbrains.buildServer.serverSide.BuildServerAdapter;
import jetbrains.buildServer.serverSide.BuildServerListener;
import jetbrains.buildServer.serverSide.SRunningBuild;
import jetbrains.buildServer.util.EventDispatcher;
import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
import java.util.Map;
public class MyEventAdapter extends BuildServerAdapter
{
private final static Logger logger = Logger.getInstance(MyEventAdapter.class.getName());
public MyEventAdapter(@NotNull EventDispatcher<BuildServerListener> serverDispatcher)
{
serverDispatcher.addListener(this);
}
@Override
public void buildFinished(@NotNull SRunningBuild build)
{
logger.debug("#");
logger.debug("# Build finished: ");
logger.debug("# name: " + build.getBuildTypeName() + ";" +
" id: " + build.getBuildId() + ";" +
" build number: " + build.getBuildNumber() + "; " +
" owner: " + build.getTriggeredBy().getUser().getName());
logger.debug("# status: " + build.getBuildStatus());
logger.debug("# ---------------------------------------------------");
super.buildFinished(build);
if (build.getBuildStatus().equals(Status.NORMAL))
{
if (someConditionCheckWhetherToTagAndPinGoesHere())
{
final String tag = "dev";
// Pin the build:
if (build.getBuildType() != null && build.getBuildType().getLastChangesSuccessfullyFinished() != null)
{
build.getBuildType().getLastChangesSuccessfullyFinished().setPinned(true, build.getOwner(), "This is a " + tag + " build.");
}
// Tag the build:
build.setTags(build.getOwner(), Arrays.asList(tag));
}
}
}
}
Вам также понадобится контекст Spring в src/main/resources/META-INF/my-plugin.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans default-autowire="constructor">
<bean class="com.foo.MyEventAdapter"/>
</beans>