Idk anything
Idk anything

Reputation: 71

TeamCity BuildRunner Plugin

I am trying to create a new buildstep into TeamCity and since you need the create a buildrunner to do so I am currently trying to create one myself.
I have created a new Mavenproject >https://confluence.jetbrains.com/display/TCD10/Developing+Plugins+Using+Maven< with the Server and Agentside command.
Now to my problem: I want to create a new buildstep and for that I did look into sample plugins from TeamCity e.g. the FxCop runner and tried to understand how it works.
I created a editParams.jsp and a viewParams.jsp in the server package. I also created a CustomRunType.java and a CustomRunTypePropertieProcessor.java.
The good thing is that the name of the buildstep is displayed in TC, but the bad thing is, when I select the custom buildstep nothing happens, I mean there ain't no textfield displayed.

editParams.jsp:

<%@ taglib prefix="props" tagdir="/WEB-INF/tags/props" %> <br>
<%@ taglib prefix="forms" tagdir="/WEB-INF/tags/forms" %><br>
<%@ taglib prefix="l" tagdir="/WEB-INF/tags/layout" %><br>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 

<jsp:useBean id="propertiesBean" scope="request" type="jetbrains.buildServer.controllers.BasePropertiesBean"/>

<l:settingsGroup title="myTitle">
    <tr>
        <th><label for="Name" title="Name">Name: <span class="mandatoryAsterix" title="Mandatory field">*</span></label></th>
            <td>
                <props:textProperty name="Name" className="longField"  />
                <span class="error" id="error_Name"></span>
                <span class="smallNote">Enter the Name.</span>
            </td>
    </tr>
</l:settingsGroup>

viewParams.jsp:

<!-- Pretty sure that here is the mistake, but no idea how to fix-->
<jsp:useBean id="propertiesBean" scope="request" type="jetbrains.buildServer.controllers.BasePropertiesBean"/>

CustomRunTypeProppertyProcessor.java:

import jetbrains.buildServer.serverSide.InvalidProperty;
import jetbrains.buildServer.serverSide.PropertiesProcessor;
import jetbrains.buildServer.util.PropertiesUtil;

import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Vector;

public class CustomRunTypePropertiesProcessor implements PropertiesProcessor {
    @Override
    public Collection<InvalidProperty> process(Map<String, String> map) {
        List<InvalidProperty> result = new Vector();
        String name = (String)map.get("Name");

        if (PropertiesUtil.isEmptyOrNull(name)) {
            result.add(new InvalidProperty("Name", "Name must be specified."));
        }
        return result;
    }
}

CustomRunType.java:

import java.util.Map;
import jetbrains.buildServer.serverSide.PropertiesProcessor;
import jetbrains.buildServer.serverSide.RunType;
import jetbrains.buildServer.serverSide.RunTypeRegistry;
import jetbrains.buildServer.web.openapi.PluginDescriptor;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class CustomRunType extends RunType {
    public CustomRunType(RunTypeRegistry runTypeRegistry, PluginDescriptor pluginDescriptor) {
        runTypeRegistry.registerRunType(this);
    }

    @NotNull
    @Override
    public String getType() {
        return "CustomPlugin";
    }

    @NotNull
    @Override
    public String getDisplayName() {
        return "CustomPlugin";
    }

    @NotNull
    @Override
    public String getDescription() {
        return "CustomPlugin";
    }

    @Nullable
    @Override
    public PropertiesProcessor getRunnerPropertiesProcessor() {
        return new CustomRunTypePropertiesProcessor();
    }

    @Nullable
    @Override
    public String getEditRunnerParamsJspFilePath() {
        return "editParams.jsp";
    }

    @Nullable
    @Override
    public String getViewRunnerParamsJspFilePath() {
        return "viewParams.jsp";
    }

    @Nullable
    @Override
    public Map<String, String> getDefaultRunnerProperties() {
        return null;
    }
}

I was wondering if someone has any idea what I did wrong, or what I forgot, or in the best case how to fix it or a simple sample for this.

Thanks for reading!

Upvotes: 3

Views: 252

Answers (1)

Ce&#39;Nedra
Ce&#39;Nedra

Reputation: 36

Normally that just happens when the path to the editParams.jsp and viewParams.jsp is not correct. Try it like this:

private final PluginDescriptor myPluginDescriptor;

public CostumRunType(final RunTypeRegistry runTypeRegistry, final 
PluginDescriptor pluginDescriptor) {
    myPluginDescriptor = pluginDescriptor;
    runTypeRegistry.registerRunType(this);
}

@Override
public String getEditRunnerParamsJspFilePath() {
  return myPluginDescriptor.getPluginResourcesPath("editRunParams.jsp");
}

@Override
public String getViewRunnerParamsJspFilePath() {
  return myPluginDescriptor.getPluginResourcesPath("viewRunParams.jsp");
}

Upvotes: 2

Related Questions