Java Code Examples for hudson.model.Run#getResult()
The following examples show how to use
hudson.model.Run#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: GitLabMessagePublisher.java From gitlab-plugin with GNU General Public License v2.0 | 6 votes |
private String getNote(Run<?, ?> build, TaskListener listener) { String message; if (this.replaceSuccessNote && build.getResult() == Result.SUCCESS) { message = replaceMacros(build, listener, this.getSuccessNoteText()); } else if (this.replaceAbortNote && build.getResult() == Result.ABORTED) { message = replaceMacros(build, listener, this.getAbortNoteText()); } else if (this.replaceUnstableNote && build.getResult() == Result.UNSTABLE) { message = replaceMacros(build, listener, this.getUnstableNoteText()); } else if (this.replaceFailureNote && build.getResult() == Result.FAILURE) { message = replaceMacros(build, listener, this.getFailureNoteText()); } else { String icon = getResultIcon(build.getResult()); String buildUrl = Jenkins.getInstance().getRootUrl() + build.getUrl(); message = MessageFormat.format("{0} Jenkins Build {1}\n\nResults available at: [Jenkins [{2} #{3}]]({4})", icon, build.getResult().toString(), build.getParent().getDisplayName(), build.getNumber(), buildUrl); } return message; }
Example 2
Source File: TelegramBotPublisher.java From telegram-notifications-plugin with MIT License | 6 votes |
@Override public void perform( @Nonnull Run<?, ?> run, @Nonnull FilePath filePath, @Nonnull Launcher launcher, @Nonnull TaskListener taskListener) throws InterruptedException, IOException { Result result = run.getResult(); boolean success = result == Result.SUCCESS && whenSuccess; boolean unstable = result == Result.UNSTABLE && whenUnstable; boolean failed = result == Result.FAILURE && whenFailed; boolean aborted = result == Result.ABORTED && whenAborted; boolean neededToSend = success || unstable || failed || aborted; if (neededToSend) { TelegramBotRunner.getInstance().getBot() .sendMessage(getMessage(), run, filePath, taskListener); } }
Example 3
Source File: DecisionMaker.java From office-365-connector-plugin with Apache License 2.0 | 5 votes |
public DecisionMaker(Run run, TaskListener listener) { this.run = run; this.taskListener = listener; Run previousBuild = run.getPreviousBuild(); previousResult = previousBuild != null ? previousBuild.getResult() : Result.SUCCESS; }
Example 4
Source File: BuildStatusAction.java From gitlab-plugin with GNU General Public License v2.0 | 5 votes |
private BuildStatus getStatus(Run<?, ?> build) { if (build == null) { return BuildStatus.NOT_FOUND; } else if (build.isBuilding()) { return BuildStatus.RUNNING; } else if (build.getResult() == Result.ABORTED) { return BuildStatus.CANCELED; } else if (build.getResult() == Result.SUCCESS) { return BuildStatus.SUCCESS; } else if (build.getResult() == Result.UNSTABLE) { return BuildStatus.UNSTABLE; } else { return BuildStatus.FAILED; } }
Example 5
Source File: GitLabMessagePublisher.java From gitlab-plugin with GNU General Public License v2.0 | 5 votes |
@Override protected void perform(Run<?, ?> build, TaskListener listener, GitLabClient client, MergeRequest mergeRequest) { try { if (!onlyForFailure || build.getResult() == Result.FAILURE || build.getResult() == Result.UNSTABLE) { client.createMergeRequestNote(mergeRequest, getNote(build, listener)); } } catch (WebApplicationException | ProcessingException e) { listener.getLogger().printf("Failed to add comment on Merge Request for project '%s': %s%n", mergeRequest.getProjectId(), e.getMessage()); LOGGER.log(Level.SEVERE, String.format("Failed to add comment on Merge Request for project '%s'", mergeRequest.getProjectId()), e); } }
Example 6
Source File: CardBuilder.java From office-365-connector-plugin with Apache License 2.0 | 5 votes |
public Card createCompletedCard(List<FactDefinition> factDefinitions) { // result might be null only for ongoing job - check documentation of Run.getCompletedResult() // but based on issue #133 it may happen that result for completed job is null Result lastResult = getCompletedResult(run); Run previousBuild = run.getPreviousBuild(); Result previousResult = previousBuild != null ? previousBuild.getResult() : Result.SUCCESS; Run lastNotFailedBuild = run.getPreviousNotFailedBuild(); boolean isRepeatedFailure = isRepeatedFailure(previousResult, lastNotFailedBuild); String summary = String.format("%s: Build %s %s", getDisplayName(), getRunName(), calculateSummary(lastResult, previousResult, isRepeatedFailure)); String status = calculateStatus(lastResult, previousResult, isRepeatedFailure); if (lastResult == Result.FAILURE) { Run failingSinceBuild = getFailingSinceBuild(lastNotFailedBuild); if (failingSinceBuild != null && previousResult == Result.FAILURE) { factsBuilder.addFailingSinceBuild(failingSinceBuild.getNumber()); } } factsBuilder.addStatus(status); factsBuilder.addRemarks(); factsBuilder.addCommitters(); factsBuilder.addDevelopers(); factsBuilder.addUserFacts(factDefinitions); Section section = buildSection(); Card card = new Card(summary, section); card.setThemeColor(getCardThemeColor(lastResult)); card.setPotentialAction(potentialActionBuilder.buildActionable()); return card; }
Example 7
Source File: JobHelper.java From github-integration-plugin with MIT License | 5 votes |
public static GHCommitState getCommitState(final Run<?, ?> run, final GHCommitState unstableAs) { GHCommitState state; Result result = run.getResult(); if (isNull(result)) { LOG.error("{} result is null.", run); state = GHCommitState.ERROR; } else if (result.isBetterOrEqualTo(SUCCESS)) { state = GHCommitState.SUCCESS; } else if (result.isBetterOrEqualTo(UNSTABLE)) { state = unstableAs; } else { state = GHCommitState.FAILURE; } return state; }
Example 8
Source File: DecisionMaker.java From office-365-connector-plugin with Apache License 2.0 | 5 votes |
private boolean isNotifyBackToNormal(Result result, Webhook webhook) { if (!webhook.isNotifyBackToNormal() || result != Result.SUCCESS) { return false; } Run previousBuild = findLastCompletedBuild(); if (previousBuild == null) { return false; } else { Result previousResult = previousBuild.getResult(); return (previousResult == Result.FAILURE || previousResult == Result.UNSTABLE); } }
Example 9
Source File: GitLabAcceptMergeRequestPublisher.java From gitlab-plugin with GNU General Public License v2.0 | 5 votes |
@Override protected void perform(Run<?, ?> build, TaskListener listener, GitLabClient client, MergeRequest mergeRequest) { try { if (build.getResult() == Result.SUCCESS) { client.acceptMergeRequest(mergeRequest, "Merge Request accepted by jenkins build success", false); } } catch (WebApplicationException | ProcessingException e) { listener.getLogger().printf("Failed to accept merge request for project '%s': %s%n", mergeRequest.getProjectId(), e.getMessage()); LOGGER.log(Level.SEVERE, String.format("Failed to accept merge request for project '%s'", mergeRequest.getProjectId()), e); } }
Example 10
Source File: MultiBranchPipelineImpl.java From blueocean-plugin with MIT License | 5 votes |
private int countRunStatus(Result result, boolean pullRequests) { Collection<Job> jobs = mbp.getAllJobs(); int count = 0; for (Job j : jobs) { if (pullRequests && isPullRequest(j) || !pullRequests && !isPullRequest(j)) { j.getBuildStatusUrl(); Run run = j.getLastBuild(); if (run != null && run.getResult() == result) { count++; } } } return count; }
Example 11
Source File: GitLabSCMRunListener.java From gitlab-branch-source-plugin with GNU General Public License v2.0 | 5 votes |
@Override public void onCompleted(Run<?, ?> build, @Nonnull TaskListener listener) { GitLabSCMHeadMetadataAction metadata = getMetadataAction(build); GitLabSCMPublishAction publishAction = build.getParent().getAction(GitLabSCMPublishAction.class); if (metadata != null && publishAction != null) { publishAction.publishResult(build, metadata); } if (build.getResult() == SUCCESS) { GitLabSCMAcceptMergeRequestAction acceptAction = build.getParent().getAction(GitLabSCMAcceptMergeRequestAction.class); if (acceptAction != null) { acceptAction.acceptMergeRequest(build, listener); } } }
Example 12
Source File: AnalysisHistory.java From warnings-ng-plugin with MIT License | 5 votes |
private static boolean hasCorrectJobResult(final Run<?, ?> run, final JobResultEvaluationMode jobResultEvaluationMode) { if (jobResultEvaluationMode == NO_JOB_FAILURE) { Result result = run.getResult(); return result != null && result.isBetterThan(Result.FAILURE); } return true; }
Example 13
Source File: GitLabSCMPublishAction.java From gitlab-branch-source-plugin with GNU General Public License v2.0 | 4 votes |
public void publishResult(Run<?, ?> build, GitLabSCMHeadMetadataAction metadata) { Result buildResult = build.getResult(); updateRunningContexts(build, metadata, toBuildStateFromResult(buildResult)); }
Example 14
Source File: GitLabPipelineStatusNotifier.java From gitlab-branch-source-plugin with MIT License | 4 votes |
/** * Sends notifications to GitLab on Checkout (for the "In Progress" Status). */ private static void sendNotifications(Run<?, ?> build, TaskListener listener) { GitLabSCMSource source = getSource(build); if (source == null) { return; } final GitLabSCMSourceContext sourceContext = getSourceContext(build, source); if (sourceContext.notificationsDisabled()) { return; } String url = getRootUrl(build); if (url.isEmpty()) { listener.getLogger().println( "Can not determine Jenkins root URL. Commit status notifications are disabled until a root URL is" + " configured in Jenkins global configuration."); return; } Result result = build.getResult(); LOGGER.log(Level.FINE, String.format("Result: %s", result)); CommitStatus status = new CommitStatus(); Constants.CommitBuildState state; status.setTargetUrl(url); if (Result.SUCCESS.equals(result)) { status.setDescription(build.getParent().getFullName() + ": This commit looks good"); status.setStatus("SUCCESS"); state = Constants.CommitBuildState.SUCCESS; } else if (Result.UNSTABLE.equals(result)) { status.setDescription( build.getParent().getFullName() + ": This commit has test failures"); status.setStatus("FAILED"); state = Constants.CommitBuildState.FAILED; } else if (Result.FAILURE.equals(result)) { status.setDescription( build.getParent().getFullName() + ": There was a failure building this commit"); status.setStatus("FAILED"); state = Constants.CommitBuildState.FAILED; } else if (result != null) { // ABORTED, NOT_BUILT. status.setDescription(build.getParent().getFullName() + ": Something is wrong with the build of this commit"); status.setStatus("CANCELED"); state = Constants.CommitBuildState.CANCELED; } else { status.setDescription(build.getParent().getFullName() + ": Build started..."); status.setStatus("RUNNING"); state = Constants.CommitBuildState.RUNNING; } final SCMRevision revision = SCMRevisionAction.getRevision(source, build); String hash; if (revision instanceof BranchSCMRevision) { listener.getLogger() .format("[GitLab Pipeline Status] Notifying branch build status: %s %s%n", status.getStatus(), status.getDescription()); hash = ((BranchSCMRevision) revision).getHash(); } else if (revision instanceof MergeRequestSCMRevision) { listener.getLogger() .format("[GitLab Pipeline Status] Notifying merge request build status: %s %s%n", status.getStatus(), status.getDescription()); hash = ((MergeRequestSCMRevision) revision).getOrigin().getHash(); } else if (revision instanceof GitTagSCMRevision) { listener.getLogger() .format("[GitLab Pipeline Status] Notifying tag build status: %s %s%n", status.getStatus(), status.getDescription()); hash = ((GitTagSCMRevision) revision).getHash(); } else { return; } status.setName(getStatusName(sourceContext, build, revision)); final JobScheduledListener jsl = ExtensionList.lookup(QueueListener.class) .get(JobScheduledListener.class); if (jsl != null) { // we are setting the status, so don't let the queue listener background thread change it to pending synchronized (jsl.resolving) { jsl.resolving.remove(build.getParent()); } } try { GitLabApi gitLabApi = GitLabHelper.apiBuilder(source.getServerName()); LOGGER.log(Level.FINE, String.format("Notifiying commit: %s", hash)); gitLabApi.getCommitsApi().addCommitStatus( source.getProjectPath(), hash, state, status); listener.getLogger().format("[GitLab Pipeline Status] Notified%n"); } catch (GitLabApiException e) { if(!e.getMessage().contains(("Cannot transition status"))) { LOGGER.log(Level.WARNING, String.format("Exception caught: %s",e.getMessage())); } } }
Example 15
Source File: JUnitResultArchiver.java From junit-plugin with MIT License | 4 votes |
public static TestResultAction parseAndAttach(@Nonnull JUnitTask task, PipelineTestDetails pipelineTestDetails, Run build, FilePath workspace, Launcher launcher, TaskListener listener) throws InterruptedException, IOException { listener.getLogger().println(Messages.JUnitResultArchiver_Recording()); final String testResults = build.getEnvironment(listener).expand(task.getTestResults()); TestResult result = parse(task, pipelineTestDetails, testResults, build, workspace, launcher, listener); synchronized (build) { // TODO can the build argument be omitted now, or is it used prior to the call to addAction? TestResultAction action = build.getAction(TestResultAction.class); boolean appending; if (action == null) { appending = false; action = new TestResultAction(build, result, listener); } else { appending = true; result.freeze(action); action.mergeResult(result, listener); } action.setHealthScaleFactor(task.getHealthScaleFactor()); // overwrites previous value if appending if (result.isEmpty()) { if (build.getResult() == Result.FAILURE) { // most likely a build failed before it gets to the test phase. // don't report confusing error message. return null; } if (task.isAllowEmptyResults()) { // User allow empty results listener.getLogger().println(Messages.JUnitResultArchiver_ResultIsEmpty()); return null; } // most likely a configuration error in the job - e.g. false pattern to match the JUnit result files throw new AbortException(Messages.JUnitResultArchiver_ResultIsEmpty()); } // TODO: Move into JUnitParser [BUG 3123310] if (task.getTestDataPublishers() != null) { for (TestDataPublisher tdp : task.getTestDataPublishers()) { Data d = tdp.contributeTestData(build, workspace, launcher, listener, result); if (d != null) { action.addData(d); } } } if (appending) { build.save(); } else { build.addAction(action); } return action; } }
Example 16
Source File: DingTalkRunListener.java From dingtalk-plugin with MIT License | 4 votes |
@Override public void onCompleted(Run<?, ?> build, @Nonnull TaskListener listener) { BuildStatusEnum statusType = null; boolean skipped = true; boolean isVerbose = globalConfig.isVerbose(); Set<String> noticeOccasions = globalConfig.getNoticeOccasions(); Result result = build.getResult(); if (isVerbose) { Logger.line(listener, LineType.START); } if (Result.SUCCESS.equals(result)) { if (noticeOccasions.contains(NoticeOccasionEnum.SUCCESS.name())) { skipped = false; statusType = BuildStatusEnum.SUCCESS; } } else if (Result.FAILURE.equals(result)) { if (noticeOccasions.contains(NoticeOccasionEnum.FAILURE.name())) { skipped = false; statusType = BuildStatusEnum.FAILURE; } } else if (Result.ABORTED.equals(result)) { if (noticeOccasions.contains(NoticeOccasionEnum.ABORTED.name())) { skipped = false; statusType = BuildStatusEnum.ABORTED; } } else if (Result.UNSTABLE.equals(result)) { if (noticeOccasions.contains(NoticeOccasionEnum.UNSTABLE.name())) { skipped = false; statusType = BuildStatusEnum.UNSTABLE; } } else if (Result.NOT_BUILT.equals(result)) { if (noticeOccasions.contains(NoticeOccasionEnum.NOT_BUILT.name())) { skipped = false; statusType = BuildStatusEnum.NOT_BUILT; } } else { statusType = BuildStatusEnum.UNKNOWN; if (isVerbose) { Logger.debug(listener, "不匹配的构建结果类型:%s", result == null ? "null" : result); } } if (skipped) { if (isVerbose) { Logger.debug(listener, "构建已结束:无匹配的通知时机,无需触发钉钉"); } return; } this.send(build, listener, statusType); if (isVerbose) { Logger.line(listener, LineType.END); } }
Example 17
Source File: PhabricatorNotifier.java From phabricator-jenkins-plugin with MIT License | 4 votes |
/** * Get the coverage provider for the build * * @param build The current build * @param listener The build listener * @return The current coverage, if any */ private CoverageProvider getCoverageProvider( Run<?, ?> build, FilePath workspace, TaskListener listener, Set<String> includeFiles) { Result buildResult; if (build.getResult() == null) { buildResult = Result.SUCCESS; } else { buildResult = build.getResult(); } if (!buildResult.isBetterOrEqualTo(Result.UNSTABLE)) { return null; } copyCoverageToJenkinsMaster(build, workspace, listener); CoverageProvider coverageProvider = null; Logger logger = new Logger(listener.getLogger()); // First check if any coverage plugins are applied. These take precedence over other providers // Only one coverage plugin provider is supported per build if (Jenkins.getInstance().getPlugin("cobertura") != null) { CoberturaBuildAction coberturaBuildAction = build.getAction(CoberturaBuildAction.class); if (coberturaBuildAction != null) { // Choose only a single coverage provider logger.info(UBERALLS_TAG, "Using coverage metrics from Cobertura Jenkins Plugin"); coverageProvider = new CoberturaPluginCoverageProvider(getCoverageReports(build), includeFiles, coberturaBuildAction); } } if (coverageProvider == null && Jenkins.getInstance().getPlugin("jacoco") != null) { JacocoBuildAction jacocoBuildAction = build.getAction(JacocoBuildAction.class); if (jacocoBuildAction != null) { logger.info(UBERALLS_TAG, "Using coverage metrics from Jacoco Jenkins Plugin"); coverageProvider = new JacocoPluginCoverageProvider(getCoverageReports(build), includeFiles, jacocoBuildAction); } } if (coverageProvider == null) { logger.info(UBERALLS_TAG, "Trying to obtain coverage metrics by parsing coverage xml files"); coverageProvider = new XmlCoverageProvider(getCoverageReports(build), includeFiles); } coverageProvider.computeCoverageIfNeeded(); cleanupCoverageFilesOnJenkinsMaster(build); if (coverageProvider.hasCoverage()) { return coverageProvider; } else { logger.info(UBERALLS_TAG, "No coverage results found"); return null; } }
Example 18
Source File: GitHubBuildStatusNotification.java From github-branch-source-plugin with MIT License | 4 votes |
private static void createBuildCommitStatus(Run<?, ?> build, TaskListener listener) { SCMSource src = SCMSource.SourceByItem.findSource(build.getParent()); SCMRevision revision = src != null ? SCMRevisionAction.getRevision(src, build) : null; if (revision != null) { // only notify if we have a revision to notify try { GitHub gitHub = lookUpGitHub(build.getParent()); try { GHRepository repo = lookUpRepo(gitHub, build.getParent()); if (repo != null) { Result result = build.getResult(); String revisionToNotify = resolveHeadCommit(revision); SCMHead head = revision.getHead(); List<AbstractGitHubNotificationStrategy> strategies = new GitHubSCMSourceContext(null, SCMHeadObserver.none()) .withTraits(((GitHubSCMSource) src).getTraits()).notificationStrategies(); for (AbstractGitHubNotificationStrategy strategy : strategies) { // TODO allow strategies to combine/cooperate on a notification GitHubNotificationContext notificationContext = GitHubNotificationContext.build(null, build, src, head); List<GitHubNotificationRequest> details = strategy.notifications(notificationContext, listener); for (GitHubNotificationRequest request : details) { boolean ignoreError = request.isIgnoreError(); try { repo.createCommitStatus(revisionToNotify, request.getState(), request.getUrl(), request.getMessage(), request.getContext()); } catch (FileNotFoundException fnfe) { if (!ignoreError) { listener.getLogger().format("%nCould not update commit status, please check if your scan " + "credentials belong to a member of the organization or a collaborator of the " + "repository and repo:status scope is selected%n%n"); if (LOGGER.isLoggable(Level.FINE)) { LOGGER.log(Level.FINE, "Could not update commit status, for run " + build.getFullDisplayName() + " please check if your scan " + "credentials belong to a member of the organization or a " + "collaborator of the repository and repo:status scope is selected", fnfe); } } } } } if (result != null) { listener.getLogger().format("%n" + Messages.GitHubBuildStatusNotification_CommitStatusSet() + "%n%n"); } } } finally { Connector.release(gitHub); } } catch (IOException ioe) { listener.getLogger().format("%n" + "Could not update commit status. Message: %s%n" + "%n", ioe.getMessage()); if (LOGGER.isLoggable(Level.FINE)) { LOGGER.log(Level.FINE, "Could not update commit status of run " + build.getFullDisplayName(), ioe); } } } }
Example 19
Source File: IssuesRecorder.java From warnings-ng-plugin with MIT License | 3 votes |
/** * Executes the build step. Used from {@link RecordIssuesStep} to provide a {@link StageResultHandler} that has * Pipeline-specific behavior. * * @param run * the run of the pipeline or freestyle job * @param workspace * workspace of the build * @param listener * the logger * @param statusHandler * reports the status for the build or for the stage */ void perform(final Run<?, ?> run, final FilePath workspace, final TaskListener listener, final StageResultHandler statusHandler) throws InterruptedException, IOException { Result overallResult = run.getResult(); if (isEnabledForFailure || overallResult == null || overallResult.isBetterOrEqualTo(Result.UNSTABLE)) { record(run, workspace, listener, statusHandler); } else { LogHandler logHandler = new LogHandler(listener, createLoggerPrefix()); logHandler.log("Skipping execution of recorder since overall result is '%s'", overallResult); } }
Example 20
Source File: ZulipNotifier.java From zulip-plugin with MIT License | 2 votes |
/** * Helper method to get build result from {@link Run}<br/> * <i>Since scripted pipeline have no post build concept, the Result variable of successful builds will<br/> * not be set yet. In that case we simply assume the build is a success</i> * * @param build The run to get build result from * @return The build result */ private static Result getBuildResult(Run<?, ?> build) { return build.getResult() != null ? build.getResult() : Result.SUCCESS; }