Where should I hook to add a build parameter?
Where is the best place to hook into BuildServerAdapter to add additional build parameters?
I'm looking to resolve issue http://jetbrains.net/jira/browse/TW-4502 through an extentions as the issue suggests.
Please sign in to leave a comment.
I've hooked using BuildServerAdapater and registered for callbacks through SBuildServer passed in through the constructor.
I've hooked into the buildStarted event, except I've run into an issue where the user can override this value by customizing the build properties for a run. Is there anyplace to hook into to prevent this action, or later in the process after the user has passed in build properties?
@Override
public void buildStarted(SRunningBuild build)
{
TriggeredBy trigger = build.getTriggeredBy();
String triggerString = trigger.getAsString();
if(trigger.isTriggeredByUser())
{
triggerString = "User:" + trigger.getUser().getUsername();
}
SimpleParameter param = new SimpleParameter("system.<corp>.TriggeredBy",triggerString);
build.getBuildType().addBuildParameter(param);
super.buildStarted(build);
}
There is a special extension point for tasks like these: jetbrains.buildServer.serverSide.ParametersPreprocessor
This extension is called before build parameters are sent to an agent. You should create your own implementation of this interface and register as Spring bean.
I can't get a ParametersPreprocessor to be registered correctly using Spring and the extenstions documentation references ExtentionsHolder which isn't in the JavaDoc's, so I can't figure out the correct arguments to pass to registerExtentions to do it manually myself.
Below is the current code.
package com.vesta.TeamCity.Extensions;
import java.util.Map;
import jetbrains.buildServer.serverSide.ParametersPreprocessor;
import jetbrains.buildServer.serverSide.SRunningBuild;
public class VestaParametersPreprocessor implements ParametersPreprocessor
{
@Override
public void fixRunBuildParameters(SRunningBuild arg0,
Map<String, String> arg1, Map<String, String> arg2)
{
arg2.put(VestaParameters.paramName, VestaParameters.convertToTriggeredByName(arg0.getTriggeredBy()));
}
}
<?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 id="VestaParameters"
init-method="register"/>
<bean id="VestaParametersPreprocessor"
/>
</beans>
This is strange, this code should work just fine. Moreover our own extensions are loaded the same way. What version of TeamCity do you use?
TeamCity 4.0.1
Could you please send source code of your plugin to teamcity-feedback [at] jetbrains.com?