1
0
Fork 0

Initial Agent Plugin Setup

We have added an agent side plugin which will be used to patch in the changes from a phabricator differential. We verify all the required settings are in place and enable the patching process after the repository have been cloned. Currently arcanist has been implemented to pull in the diff we are going to build upon that is the next step.
This commit is contained in:
Steven Cooney 2019-06-04 11:18:50 +01:00
parent a97efb1597
commit 8d56fa3128
3 changed files with 80 additions and 4 deletions

View file

@ -0,0 +1,77 @@
package uk.xlab.teamcity.phabricator;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import org.jetbrains.annotations.NotNull;
import jetbrains.buildServer.agent.AgentBuildFeature;
import jetbrains.buildServer.agent.AgentLifeCycleAdapter;
import jetbrains.buildServer.agent.AgentLifeCycleListener;
import jetbrains.buildServer.agent.AgentRunningBuild;
import jetbrains.buildServer.agent.BuildProgressLogger;
import jetbrains.buildServer.util.EventDispatcher;
public class AgentBuildExtension extends AgentLifeCycleAdapter {
private PhabricatorAgentLogger agentLogLogger;
private BuildProgressLogger buildLogger;
private PhabricatorPluginConfig phabricatorConfig;
private boolean phabricatorTriggeredBuild = false;
public AgentBuildExtension(@NotNull final EventDispatcher<AgentLifeCycleListener> eventDispatcher,
@NotNull final PhabricatorAgentLogger phabLogger) {
eventDispatcher.addListener(this);
agentLogLogger = phabLogger;
phabricatorConfig = new PhabricatorPluginConfig();
phabricatorConfig.setLogger(agentLogLogger);
}
@Override
public void buildStarted(@NotNull AgentRunningBuild runningBuild) {
// Setup logger to print to build output
buildLogger = runningBuild.getBuildLogger();
// Attempt to get the parameters set by the phabricator build feature. If non
// are set then the feature is not turned on.
Collection<AgentBuildFeature> phabricatorBuildFeatureParameters = runningBuild
.getBuildFeaturesOfType(Constants.BUILD_FEATURE_TYPE);
if (phabricatorBuildFeatureParameters.isEmpty()) {
return;
}
// Check that the relevant build and phabricator settings/configurations are
// present
Map<String, String> params = new HashMap<>();
params.putAll(phabricatorBuildFeatureParameters.iterator().next().getParameters());
params.putAll(runningBuild.getSharedConfigParameters());
// Setup plugin specific configuration
phabricatorConfig.setParameters(params);
// Now we have set all the parameters we need to check if
// everything is present and correct for us to continue
if (!phabricatorConfig.isPluginSetup()) {
agentLogLogger.info("Plugin incorrectly configured");
return;
}
phabricatorTriggeredBuild = true;
agentLogLogger.info("Plugin ready");
buildLogger.message("Phabricator Plugin - Active");
}
@Override
public void sourcesUpdated(@NotNull AgentRunningBuild runningBuild) {
if (!phabricatorTriggeredBuild) {
return;
}
buildLogger.message("PHAB: SOURCES HAVE UPDATED");
agentLogLogger.info("PHAB: SOURCES HAVE UPDATED");
}
}

View file

@ -1,4 +0,0 @@
package uk.xlab.teamcity.phabricator;
public class AppAgent {
}

View file

@ -4,4 +4,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"
default-autowire="constructor"> default-autowire="constructor">
<bean class="uk.xlab.teamcity.phabricator.AgentBuildExtension" />
<bean class="uk.xlab.teamcity.phabricator.PhabricatorAgentLogger" />
</beans> </beans>