Add TeamCity Agent
Add a TeamCity agent to which run after the VCS sources have been applied to trigger arcanist patch and pull in any changes from the specified Phabricator revision onto master and verify they build.
This commit is contained in:
parent
abfa8f840d
commit
ef0656b1de
3 changed files with 105 additions and 4 deletions
|
@ -16,6 +16,7 @@ import uk.xlab.teamcity.phabricator.logging.PhabricatorAgentLogger;
|
||||||
|
|
||||||
public class AgentBuildExtension extends AgentLifeCycleAdapter {
|
public class AgentBuildExtension extends AgentLifeCycleAdapter {
|
||||||
|
|
||||||
|
private static final String OUTPUT_PREFIX = "Phabricator Plugin - %s";
|
||||||
private PhabricatorAgentLogger agentLogLogger;
|
private PhabricatorAgentLogger agentLogLogger;
|
||||||
private BuildProgressLogger buildLogger;
|
private BuildProgressLogger buildLogger;
|
||||||
private PhabricatorPluginConfig phabricatorConfig;
|
private PhabricatorPluginConfig phabricatorConfig;
|
||||||
|
@ -57,12 +58,26 @@ public class AgentBuildExtension extends AgentLifeCycleAdapter {
|
||||||
// everything is present and correct for us to continue
|
// everything is present and correct for us to continue
|
||||||
if (!phabricatorConfig.isPluginSetup()) {
|
if (!phabricatorConfig.isPluginSetup()) {
|
||||||
agentLogLogger.info("Plugin incorrectly configured");
|
agentLogLogger.info("Plugin incorrectly configured");
|
||||||
|
phabricatorTriggeredBuild = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
phabricatorTriggeredBuild = true;
|
phabricatorTriggeredBuild = true;
|
||||||
agentLogLogger.info("Plugin ready");
|
agentLogLogger.info("Plugin ready");
|
||||||
buildLogger.message("Phabricator Plugin - Active");
|
buildLogger.message(String.format(OUTPUT_PREFIX, "Active"));
|
||||||
|
|
||||||
|
buildLogger.message(String.format(OUTPUT_PREFIX, String.format("%s: %s", Constants.PHABRICATOR_URL_SETTING,
|
||||||
|
phabricatorConfig.getPhabricatorURL().toString())));
|
||||||
|
buildLogger.message(String.format(OUTPUT_PREFIX, String.format("%s: %s",
|
||||||
|
Constants.PHABRICATOR_ARCANIST_PATH_SETTING, phabricatorConfig.getPathToArcanist())));
|
||||||
|
buildLogger.message(String.format(OUTPUT_PREFIX,
|
||||||
|
String.format("%s: %s", Constants.BUILD_ID, phabricatorConfig.getBuildId())));
|
||||||
|
buildLogger.message(String.format(OUTPUT_PREFIX,
|
||||||
|
String.format("%s: %s", Constants.DIFF_ID, phabricatorConfig.getDiffId())));
|
||||||
|
buildLogger.message(String.format(OUTPUT_PREFIX, String.format("%s: %s", Constants.HARBORMASTER_PHID,
|
||||||
|
phabricatorConfig.getPhabricatorURL().toString())));
|
||||||
|
buildLogger.message(String.format(OUTPUT_PREFIX,
|
||||||
|
String.format("%s: %s", Constants.REVISION_ID, phabricatorConfig.getRevisionId())));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -72,7 +87,17 @@ public class AgentBuildExtension extends AgentLifeCycleAdapter {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
buildLogger.message("PHAB: SOURCES HAVE UPDATED");
|
buildLogger.message(String.format(OUTPUT_PREFIX, "Attempting arc patch"));
|
||||||
agentLogLogger.info("PHAB: SOURCES HAVE UPDATED");
|
agentLogLogger.info("Attempting arc patch");
|
||||||
|
|
||||||
|
ArcanistClient arcanistClient = new ArcanistClient(phabricatorConfig.getPathToArcanist(),
|
||||||
|
runningBuild.getCheckoutDirectory().getPath(), phabricatorConfig.getPhabricatorURL().toString(),
|
||||||
|
phabricatorConfig.getConduitToken(), agentLogLogger);
|
||||||
|
|
||||||
|
int patchCode = arcanistClient.patch(phabricatorConfig.getDiffId());
|
||||||
|
|
||||||
|
if (patchCode > 0) {
|
||||||
|
runningBuild.stopBuild("Patch failed to apply. Check the agent output log for patch failure detals.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,50 @@
|
||||||
|
package uk.xlab.teamcity.phabricator;
|
||||||
|
|
||||||
|
import uk.xlab.teamcity.phabricator.logging.PhabricatorAgentLogger;
|
||||||
|
|
||||||
|
public class ArcanistClient {
|
||||||
|
|
||||||
|
private final String arcPath;
|
||||||
|
private final String workingDir;
|
||||||
|
private final String conduitAPI;
|
||||||
|
private final String token;
|
||||||
|
|
||||||
|
private final PhabricatorAgentLogger agentLogLogger;
|
||||||
|
|
||||||
|
public ArcanistClient(
|
||||||
|
final String pathToArcanist,
|
||||||
|
final String workingDirectory,
|
||||||
|
final String phabricatorURL,
|
||||||
|
final String conduitToken,
|
||||||
|
final PhabricatorAgentLogger logger
|
||||||
|
) {
|
||||||
|
arcPath = pathToArcanist;
|
||||||
|
workingDir = workingDirectory;
|
||||||
|
conduitAPI = phabricatorURL;
|
||||||
|
token = conduitToken;
|
||||||
|
agentLogLogger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int patch(String diffId) {
|
||||||
|
try {
|
||||||
|
|
||||||
|
Command commandToExecute = new CommandBuilder()
|
||||||
|
.setCommand(arcPath)
|
||||||
|
.setAction("patch")
|
||||||
|
.setWorkingDir(workingDir)
|
||||||
|
.setArg("--diff")
|
||||||
|
.setArg(diffId)
|
||||||
|
.setFlagWithValueEquals("--conduit-uri", conduitAPI)
|
||||||
|
.setFlagWithValueEquals("--conduit-token", token)
|
||||||
|
.build();
|
||||||
|
return commandToExecute.executeAndWait();
|
||||||
|
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
agentLogLogger.warn("Building command failed", e);
|
||||||
|
} catch (Exception e) {
|
||||||
|
agentLogLogger.warn("Patching error", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
|
@ -48,6 +48,15 @@ public class PhabricatorPluginConfig {
|
||||||
* @param parameters
|
* @param parameters
|
||||||
*/
|
*/
|
||||||
public void setParameters(Map<String, String> parameters) {
|
public void setParameters(Map<String, String> parameters) {
|
||||||
|
// Clear the class variables to avoid any lingering references
|
||||||
|
phabricatorUrl = null;
|
||||||
|
conduitToken = null;
|
||||||
|
pathToArcanist = null;
|
||||||
|
buildId = null;
|
||||||
|
diffId = null;
|
||||||
|
harbormasterPHID = null;
|
||||||
|
revisionId = null;
|
||||||
|
|
||||||
params = parameters;
|
params = parameters;
|
||||||
|
|
||||||
logger.info("Looking for parameters");
|
logger.info("Looking for parameters");
|
||||||
|
@ -71,7 +80,8 @@ public class PhabricatorPluginConfig {
|
||||||
conduitToken = params.get(Constants.PHABRICATOR_CONDUIT_TOKEN_SETTING);
|
conduitToken = params.get(Constants.PHABRICATOR_CONDUIT_TOKEN_SETTING);
|
||||||
break;
|
break;
|
||||||
case Constants.PHABRICATOR_ARCANIST_PATH_SETTING:
|
case Constants.PHABRICATOR_ARCANIST_PATH_SETTING:
|
||||||
logger.info(String.format("Found Phabricator Arcanist Path: %s", params.get(Constants.PHABRICATOR_ARCANIST_PATH_SETTING)));
|
logger.info(String.format("Found Phabricator Arcanist Path: %s",
|
||||||
|
params.get(Constants.PHABRICATOR_ARCANIST_PATH_SETTING)));
|
||||||
pathToArcanist = params.get(Constants.PHABRICATOR_ARCANIST_PATH_SETTING);
|
pathToArcanist = params.get(Constants.PHABRICATOR_ARCANIST_PATH_SETTING);
|
||||||
break;
|
break;
|
||||||
case Constants.BUILD_ID:
|
case Constants.BUILD_ID:
|
||||||
|
@ -116,10 +126,26 @@ public class PhabricatorPluginConfig {
|
||||||
return conduitToken;
|
return conduitToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getPathToArcanist() {
|
||||||
|
return pathToArcanist;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getBuildId() {
|
||||||
|
return buildId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDiffId() {
|
||||||
|
return diffId;
|
||||||
|
}
|
||||||
|
|
||||||
public String getHarbormasterPHID() {
|
public String getHarbormasterPHID() {
|
||||||
return harbormasterPHID;
|
return harbormasterPHID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getRevisionId() {
|
||||||
|
return revisionId;
|
||||||
|
}
|
||||||
|
|
||||||
private URL parsePhabricatorURL(String input) throws MalformedURLException {
|
private URL parsePhabricatorURL(String input) throws MalformedURLException {
|
||||||
URL inputURL = new URL(input);
|
URL inputURL = new URL(input);
|
||||||
return inputURL;
|
return inputURL;
|
||||||
|
|
Loading…
Reference in a new issue