Java Code Examples for hudson.model.AbstractBuild#getResult()

The following examples show how to use hudson.model.AbstractBuild#getResult() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: QGPublisher.java    From sonar-quality-gates-plugin with MIT License 5 votes vote down vote up
@Override
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) {

    Result result = build.getResult();

    if (Result.SUCCESS != result) {
        listener.getLogger().println("Previous steps failed the build.\nResult is: " + result);

        return false;
    }

    boolean buildHasPassed = false;

    try {
        JobConfigData checkedJobConfigData = jobConfigurationService.checkProjectKeyIfVariable(jobConfigData, build, listener);
        buildHasPassed = buildDecision.getStatus(globalConfigDataForSonarInstance, checkedJobConfigData, listener);

        if ("".equals(jobConfigData.getSonarInstanceName())) {
            listener.getLogger().println(JobExecutionService.DEFAULT_CONFIGURATION_WARNING);
        }

        listener.getLogger().println("PostBuild-Step: Quality Gates plugin build passed: " + String.valueOf(buildHasPassed).toUpperCase());

        if (!buildHasPassed && BuildStatusEnum.UNSTABLE.equals(checkedJobConfigData.getBuildStatus())) {
            build.setResult(Result.UNSTABLE);
            return true;
        }
    } catch (QGException e) {
        e.printStackTrace(listener.getLogger());
    }

    return buildHasPassed;
}
 
Example 2
Source File: NotifyQQ.java    From NotifyQQ with MIT License 5 votes vote down vote up
@Override
public boolean perform(AbstractBuild build, Launcher launcher, BuildListener listener) throws UnsupportedEncodingException {

    logger = listener.getLogger();

    Jenkins.getInstance();
    String jobURL = "";
    try {
        jobURL = build.getEnvironment(listener).expand("${JOB_URL}");
        logger.println("jobURL = " + jobURL);
    } catch (Exception e) {
        logger.println("tokenmacro expand error.");
    }

    String msg = "各位小伙伴,项目";
    msg += build.getFullDisplayName();
    if (build.getResult() == Result.SUCCESS) {
        msg += "编译成功!" + qqmessage;
    } else {
        msg += "编译失败了...";
        msg += "jenkins地址:" + jobURL;
    }

    msg = URLEncoder.encode(msg, "UTF-8");
    msg = msg.replaceAll("\\+", "_");

    for (int i = 0; i < qQNumbers.size(); i++) {
        QQNumber number = qQNumbers.get(i);
        send(GenerateMessageURL(number.GetUrlString(), msg));
    }

    return true;
}
 
Example 3
Source File: BuildNotifier.java    From build-notifications-plugin with MIT License 5 votes vote down vote up
/**
 * Constructs a new BuildNotifier based on the given objects
 *
 * @param message the message to populate and send
 * @param build   the target build
 */
public BuildNotifier(Message message, AbstractBuild build, String baseUrl) {
  this.message = message;
  this.build = build;
  this.status = BuildStatus.of(build);
  this.result = build.getResult();
  this.baseUrl = baseUrl;
}
 
Example 4
Source File: GitLabCommitStatusPublisher.java    From gitlab-plugin with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
    Result buildResult = build.getResult();
    if (buildResult == Result.SUCCESS || (buildResult == Result.UNSTABLE && markUnstableAsSuccess)) {
        CommitStatusUpdater.updateCommitStatus(build, listener, BuildState.success, name);
    } else if (buildResult == Result.ABORTED) {
        CommitStatusUpdater.updateCommitStatus(build, listener, BuildState.canceled, name);
    } else {
        CommitStatusUpdater.updateCommitStatus(build, listener, BuildState.failed, name);
    }
    return true;
}
 
Example 5
Source File: DashboardView.java    From jenkins-deployment-dashboard-plugin with MIT License 4 votes vote down vote up
@JavaScriptMethod
public String deploy(String version, String environment) {
    LOGGER.info("Deploy version " + version + " to environment " + environment);

    // Get the environment with corresponding build-job
    Environment buildEnvironment = null;
    for (Environment env : environments) {
        if (env.getAwsInstance().equals(environment)) {
            buildEnvironment = env;
            break;
        }
    }

    final AbstractProject buildJob = Jenkins.getInstance().getItemByFullName(buildEnvironment.getBuildJob(), AbstractProject.class);
    LOGGER.info("Executing job: " + buildJob);

    if (buildJob == null) {
        return String.format(Messages.DashboardView_buildJobNotFound(), buildEnvironment.getName());
    }

    if ((!buildJob.isBuildable()) || (!buildJob.isParameterized())) {
        return Messages.DashboardView_deploymentCannotBeExecuted();
    }

    final ParametersAction versionParam = new ParametersAction(new StringParameterValue(PARAM_VERSION, version));
    final ParametersAction environmentParam = new ParametersAction(new StringParameterValue(PARAM_ENVIRONMENT, environment));
    final ParametersAction ec2RegionParam = new ParametersAction(new StringParameterValue(PARAM_EC2_REGION, environment));
    final ParametersAction awsKeyParam = new ParametersAction(new StringParameterValue(PARAM_AWS_KEY, environment));

    List<ParametersAction> actions = Arrays.asList(versionParam, environmentParam, ec2RegionParam, awsKeyParam);
    QueueTaskFuture<AbstractBuild> scheduledBuild = buildJob.scheduleBuild2(2, new Cause.UserIdCause(), actions);

    Result result = Result.FAILURE;
    try {
        AbstractBuild finishedBuild = scheduledBuild.get();
        result = finishedBuild.getResult();
        LOGGER.info("Build finished with result: " + result + " completed in: " + finishedBuild.getDurationString() + ". ");
    } catch (Exception e) {
        LOGGER.severe("Error while waiting for build " + scheduledBuild.toString() + ".");
        LOGGER.severe(e.getMessage());
        LOGGER.severe(ExceptionUtils.getFullStackTrace(e));
        return String.format(Messages.DashboardView_buildJobFailed(), buildJob.getName());
    }
    if (result == Result.SUCCESS) {
        return String.format(Messages.DashboardView_buildJobScheduledSuccessfully(), buildJob.getName());
    }
    return String.format(Messages.DashboardView_buildJobSchedulingFailed(), buildJob.getName());
}