Search in sources :

Example 1 with SendHarbormasterUriTask

use of com.uber.jenkins.phabricator.tasks.SendHarbormasterUriTask in project phabricator-jenkins-plugin by uber.

the class PhabricatorBuildWrapper method setUp.

/**
 * {@inheritDoc}
 */
@Override
public Environment setUp(AbstractBuild build, Launcher launcher, BuildListener listener) throws IOException, InterruptedException {
    EnvVars environment = build.getEnvironment(listener);
    Logger logger = new Logger(listener.getLogger());
    if (environment == null) {
        return this.ignoreBuild(logger, "No environment variables found?!");
    }
    final Map<String, String> envAdditions = new HashMap<String, String>();
    String phid = environment.get(PhabricatorPlugin.PHID_FIELD);
    String diffID = environment.get(PhabricatorPlugin.DIFFERENTIAL_ID_FIELD);
    if (CommonUtils.isBlank(diffID)) {
        this.addShortText(build);
        this.ignoreBuild(logger, "No differential ID found.");
        return new Environment() {
        };
    }
    FilePath arcWorkPath;
    if (this.workDir != null && this.workDir.length() > 0) {
        arcWorkPath = build.getWorkspace().child(workDir);
    } else {
        arcWorkPath = build.getWorkspace();
    }
    LauncherFactory starter = new LauncherFactory(launcher, environment, listener.getLogger(), arcWorkPath);
    ConduitAPIClient conduitClient;
    try {
        conduitClient = getConduitClient(build.getParent(), logger);
    } catch (ConduitAPIException e) {
        e.printStackTrace(logger.getStream());
        logger.warn(CONDUIT_TAG, e.getMessage());
        return null;
    }
    DifferentialClient diffClient = new DifferentialClient(diffID, conduitClient);
    if (!CommonUtils.isBlank(phid)) {
        logger.info("harbormaster", "Sending Harbormaster BUILD_URL via PHID: " + phid);
        String buildUrl = environment.get("BUILD_URL");
        Task.Result sendUriResult = new SendHarbormasterUriTask(logger, diffClient, phid, buildUrl).run();
        if (sendUriResult != Task.Result.SUCCESS) {
            logger.info("harbormaster", "Unable to send BUILD_URL to Harbormaster");
        }
    }
    Differential diff;
    try {
        diff = new Differential(diffClient.fetchDiff());
        diff.setCommitMessage(diffClient.getCommitMessage(diff.getRevisionID(false)));
        diff.decorate(build, this.getPhabricatorURL(build.getParent()));
        logger.info(CONDUIT_TAG, "Fetching differential from Conduit API");
        envAdditions.put(DIFFERENTIAL_AUTHOR, diff.getAuthorEmail());
        envAdditions.put(DIFFERENTIAL_BASE_COMMIT, diff.getBaseCommit());
        envAdditions.put(DIFFERENTIAL_BRANCH, diff.getBranch());
        envAdditions.put(DIFFERENTIAL_SUMMARY, diff.getCommitMessage());
    } catch (ConduitAPIException e) {
        e.printStackTrace(logger.getStream());
        logger.warn(CONDUIT_TAG, "Unable to fetch differential from Conduit API");
        logger.warn(CONDUIT_TAG, e.getMessage());
        return null;
    }
    String baseCommit = "origin/master";
    if (!applyToMaster) {
        baseCommit = diff.getBaseCommit();
    }
    final String conduitToken = this.getConduitToken(build.getParent(), logger);
    Task.Result result = new ApplyPatchTask(logger, starter, baseCommit, diffID, conduitToken, getArcPath(), DEFAULT_GIT_PATH, createCommit, skipForcedClean, createBranch, patchWithForceFlag, scmType).run();
    if (result != Task.Result.SUCCESS) {
        logger.warn("arcanist", "Error applying arc patch; got non-zero exit code " + result);
        Task.Result failureResult = new SendHarbormasterResultTask(logger, diffClient, phid, false, null, null, null).run();
        if (failureResult != Task.Result.SUCCESS) {
            // such failure, very broke
            logger.warn("arcanist", "Unable to notify harbormaster of patch failure");
        }
        // Indicate failure
        return null;
    }
    return new Environment() {

        @Override
        public void buildEnvVars(Map<String, String> env) {
            EnvVars envVars = new EnvVars(env);
            envVars.putAll(envAdditions);
            env.putAll(envVars);
        }
    };
}
Also used : FilePath(hudson.FilePath) SendHarbormasterUriTask(com.uber.jenkins.phabricator.tasks.SendHarbormasterUriTask) ApplyPatchTask(com.uber.jenkins.phabricator.tasks.ApplyPatchTask) SendHarbormasterResultTask(com.uber.jenkins.phabricator.tasks.SendHarbormasterResultTask) Task(com.uber.jenkins.phabricator.tasks.Task) SendHarbormasterResultTask(com.uber.jenkins.phabricator.tasks.SendHarbormasterResultTask) Differential(com.uber.jenkins.phabricator.conduit.Differential) HashMap(java.util.HashMap) ConduitAPIException(com.uber.jenkins.phabricator.conduit.ConduitAPIException) DifferentialClient(com.uber.jenkins.phabricator.conduit.DifferentialClient) ConduitAPIClient(com.uber.jenkins.phabricator.conduit.ConduitAPIClient) Logger(com.uber.jenkins.phabricator.utils.Logger) SendHarbormasterUriTask(com.uber.jenkins.phabricator.tasks.SendHarbormasterUriTask) EnvVars(hudson.EnvVars) ApplyPatchTask(com.uber.jenkins.phabricator.tasks.ApplyPatchTask) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with SendHarbormasterUriTask

use of com.uber.jenkins.phabricator.tasks.SendHarbormasterUriTask in project phabricator-jenkins-plugin by uber.

the class BuildResultProcessor method processHarbormaster.

/**
 * Send Harbormaster result to Phabricator
 *
 * @return whether we were able to successfully send the result
 */
public boolean processHarbormaster() {
    final boolean harbormasterSuccess = getBuildResult().isBetterOrEqualTo(Result.SUCCESS);
    if (runHarbormaster) {
        logger.info("harbormaster", "Sending Harbormaster BUILD_URL via PHID: " + phid);
        Task.Result sendUriResult = new SendHarbormasterUriTask(logger, diffClient, phid, buildUrl).run();
        if (sendUriResult != Task.Result.SUCCESS) {
            logger.info(LOGGING_TAG, "Unable to send BUILD_URL to Harbormaster. " + "This can be safely ignored, and is usually because it's already set.");
        }
        if (unitResults != null) {
            logger.info(LOGGING_TAG, String.format("Publishing unit results to Harbormaster for %d tests.", unitResults.getResults().size()));
        }
        if (harbormasterCoverage != null) {
            logger.info(LOGGING_TAG, String.format("Publishing coverage data to Harbormaster for %d files.", harbormasterCoverage.size()));
        }
        if (lintResults != null) {
            logger.info(LOGGING_TAG, String.format("Publishing lint results for %d violations", lintResults.getResults().size()));
        }
        logger.info(LOGGING_TAG, String.format("Sending build result to Harbormaster with PHID %s, success: %s", phid, harbormasterSuccess));
        Task.Result result = new SendHarbormasterResultTask(logger, diffClient, phid, harbormasterSuccess, unitResults, harbormasterCoverage, lintResults).run();
        if (result != Task.Result.SUCCESS) {
            return false;
        }
    } else {
        logger.info("uberalls", "Harbormaster integration not enabled for this build.");
        if (getBuildResult().isBetterOrEqualTo(Result.SUCCESS)) {
            commentAction = "resign";
        } else if (getBuildResult().isWorseOrEqualTo(Result.UNSTABLE)) {
            commentAction = "reject";
        }
    }
    return true;
}
Also used : SendHarbormasterUriTask(com.uber.jenkins.phabricator.tasks.SendHarbormasterUriTask) PostCommentTask(com.uber.jenkins.phabricator.tasks.PostCommentTask) SendHarbormasterResultTask(com.uber.jenkins.phabricator.tasks.SendHarbormasterResultTask) Task(com.uber.jenkins.phabricator.tasks.Task) SendHarbormasterUriTask(com.uber.jenkins.phabricator.tasks.SendHarbormasterUriTask) SendHarbormasterResultTask(com.uber.jenkins.phabricator.tasks.SendHarbormasterResultTask)

Aggregations

SendHarbormasterResultTask (com.uber.jenkins.phabricator.tasks.SendHarbormasterResultTask)2 SendHarbormasterUriTask (com.uber.jenkins.phabricator.tasks.SendHarbormasterUriTask)2 Task (com.uber.jenkins.phabricator.tasks.Task)2 ConduitAPIClient (com.uber.jenkins.phabricator.conduit.ConduitAPIClient)1 ConduitAPIException (com.uber.jenkins.phabricator.conduit.ConduitAPIException)1 Differential (com.uber.jenkins.phabricator.conduit.Differential)1 DifferentialClient (com.uber.jenkins.phabricator.conduit.DifferentialClient)1 ApplyPatchTask (com.uber.jenkins.phabricator.tasks.ApplyPatchTask)1 PostCommentTask (com.uber.jenkins.phabricator.tasks.PostCommentTask)1 Logger (com.uber.jenkins.phabricator.utils.Logger)1 EnvVars (hudson.EnvVars)1 FilePath (hudson.FilePath)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1