Java Code Examples for hudson.model.Run#getCause()
The following examples show how to use
hudson.model.Run#getCause() .
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: GitLabWebHookEnvironmentContributor.java From gitlab-branch-source-plugin with MIT License | 6 votes |
@Override public void buildEnvironmentFor(@Nonnull Run r, @Nonnull EnvVars envs, @Nonnull TaskListener listener) { GitLabWebHookCause gitLabWebHookCause = null; if (r instanceof WorkflowRun) { gitLabWebHookCause = (GitLabWebHookCause) r.getCause(GitLabWebHookCause.class); } envs.override("GITLAB_OBJECT_KIND", "none"); if (gitLabWebHookCause != null) { if(gitLabWebHookCause.getGitLabPushCauseData() != null) { envs.overrideAll(gitLabWebHookCause.getGitLabPushCauseData().getBuildVariables()); } else if(gitLabWebHookCause.getGitLabMergeRequestCauseData() != null) { envs.overrideAll(gitLabWebHookCause.getGitLabMergeRequestCauseData().getBuildVariables()); } else if(gitLabWebHookCause.getGitLabTagPushCauseData() != null) { envs.overrideAll(gitLabWebHookCause.getGitLabTagPushCauseData().getBuildVariables()); } } }
Example 2
Source File: InfluxDbNotifier.java From github-autostatus-plugin with MIT License | 6 votes |
private void notifyCoverage(String jobName, @Nullable CodeCoverage coverageInfo, Run<?, ?> run) { if (coverageInfo != null) { String buildUrl = run.getUrl(); int buildNumber = run.getNumber(); Cause cause = run.getCause(Cause.class); String buildCause = cause == null ? BuildNotifierConstants.DEFAULT_STRING : cause.getShortDescription(); String data = config.getSchema().formatCoverage(jobName, repoOwner, repoName, branchName, coverageInfo.getClasses(), coverageInfo.getConditionals(), coverageInfo.getFiles(), coverageInfo.getLines(), coverageInfo.getMethods(), coverageInfo.getPackages(), coverageInfo.getInstructions(), buildUrl, buildNumber, buildCause); postData(data); } }
Example 3
Source File: InfluxDbNotifier.java From github-autostatus-plugin with MIT License | 6 votes |
private void notifyTestResults(String jobName, @Nullable TestResults testResults, Run<?, ?> run) { if (testResults != null) { String buildUrl = run.getUrl(); int buildNumber = run.getNumber(); Cause cause = run.getCause(Cause.class); String buildCause = cause == null ? BuildNotifierConstants.DEFAULT_STRING : cause.getShortDescription(); String data = config.getSchema().formatTests(jobName, repoOwner, repoName, branchName, testResults.getPassedTestCaseCount(), testResults.getSkippedTestCaseCount(), testResults.getFailedTestCaseCount(), buildUrl, buildNumber, buildCause); postData(data); for (TestSuite testSuite : testResults.getTestSuites()) { notifyTestSuite(jobName, testSuite, run); } } }
Example 4
Source File: InfluxDbNotifier.java From github-autostatus-plugin with MIT License | 6 votes |
private String notifyTestCase(String jobName, String suiteName, TestCase testCase, Run<?, ?> run) { String buildUrl = run.getUrl(); int buildNumber = run.getNumber(); Cause cause = run.getCause(Cause.class); String buildCause = cause == null ? BuildNotifierConstants.DEFAULT_STRING : cause.getShortDescription(); String data = config.getSchema().formatTestCase(jobName, repoOwner, repoName, branchName, suiteName, testCase.getName(), testCase.getPassedCount(), testCase.getSkippedCount(), testCase.getFailedCount(), buildUrl, buildNumber, buildCause); return data; }
Example 5
Source File: HttpNotifier.java From github-autostatus-plugin with MIT License | 6 votes |
private BuildStatus constructBuildStatus(BuildStage.State buildState, Map<String, Object> parameters) { Run<?, ?> run = (Run<?, ?>) parameters.get(BuildNotifierConstants.BUILD_OBJECT); String jobName = (String) parameters.getOrDefault(BuildNotifierConstants.JOB_NAME, BuildNotifierConstants.DEFAULT_STRING); long blockedDuration = BuildNotifierConstants.getLong(parameters, BuildNotifierConstants.BLOCKED_DURATION); String buildUrl = run.getUrl(); int buildNumber = run.getNumber(); long buildDuration = BuildNotifierConstants.getLong(parameters, BuildNotifierConstants.JOB_DURATION) - blockedDuration; Cause cause = run.getCause(Cause.class); String buildCause = cause == null ? BuildNotifierConstants.DEFAULT_STRING : cause.getShortDescription(); BuildStatus result = new org.jenkinsci.plugins.githubautostatus.model.BuildStatus(); result.setRepoOwner(repoOwner); result.setRepoName(repoName); result.setJobName(jobName); result.setBranch(branchName); result.setBuildUrl(buildUrl); result.setBuildNumber(buildNumber); result.setTrigger(buildCause); result.setBlocked(blockedDuration > 0); result.setBlockedTime(blockedDuration); result.setDuration(buildDuration); result.setPassed(buildState == BuildStage.State.CompletedSuccess); result.setResult(buildState); result.setTimestamp(Clock.system(TimeZone.getTimeZone("UTC").toZoneId()).millis() / 1000); return result; }
Example 6
Source File: InfluxDbNotifier.java From github-autostatus-plugin with MIT License | 5 votes |
/** * Sends the final build status to InfluxDB. * * @param buildState the new state * @param parameters build parameters */ @Override public void notifyFinalBuildStatus(BuildStage.State buildState, Map<String, Object> parameters) { Run<?, ?> run = (Run<?, ?>) parameters.get(BuildNotifierConstants.BUILD_OBJECT); String jobName = (String) parameters.getOrDefault(BuildNotifierConstants.JOB_NAME, BuildNotifierConstants.DEFAULT_STRING); int passed = buildState == BuildStage.State.CompletedSuccess ? 1 : 0; long blockedDuration = BuildNotifierConstants.getLong(parameters, BuildNotifierConstants.BLOCKED_DURATION); int blocked = blockedDuration > 0 ? 1 : 0; String buildUrl = run.getUrl(); int buildNumber = run.getNumber(); Cause cause = run.getCause(Cause.class); String buildCause = cause == null ? BuildNotifierConstants.DEFAULT_STRING : cause.getShortDescription(); String data = config.getSchema().formatJob(jobName, repoOwner, repoName, branchName, buildState.toString(), blocked, BuildNotifierConstants.getLong(parameters, BuildNotifierConstants.JOB_DURATION) - blockedDuration, blockedDuration, passed, buildUrl, buildNumber, buildCause); postData(data); if (!this.config.getIgnoreSendingTestResultsToInflux()) { notifyTestResults(jobName, (TestResults) parameters.get(BuildNotifierConstants.TEST_CASE_INFO), run); } if (!this.config.getIgnoreSendingTestCoverageToInflux()) { notifyCoverage(jobName, (CodeCoverage) parameters.get(BuildNotifierConstants.COVERAGE_INFO), run); } }
Example 7
Source File: InfluxDbNotifier.java From github-autostatus-plugin with MIT License | 5 votes |
private void notifyTestSuite(String jobName, TestSuite testSuite, Run<?, ?> run) { String suiteName = testSuite.getName(); String buildUrl = run.getUrl(); int buildNumber = run.getNumber(); Cause cause = run.getCause(Cause.class); String buildCause = cause == null ? BuildNotifierConstants.DEFAULT_STRING : cause.getShortDescription(); List<String> testSuiteQuery = new ArrayList<>(); String data = config.getSchema().formatTestSuite(jobName, repoOwner, repoName, branchName, suiteName, testSuite.getDuration(), testSuite.getPassedTestCaseCount(), testSuite.getSkippedTestCaseCount(), testSuite.getFailedTestCaseCount(), buildUrl, buildNumber, buildCause); testSuiteQuery.add(data); for (TestCase testCase : testSuite.getTestCases()) { testSuiteQuery.add(notifyTestCase(jobName, suiteName, testCase, run)); } postData(String.join("\\n", testSuiteQuery)); }
Example 8
Source File: JobHelper.java From github-integration-plugin with MIT License | 5 votes |
/** * matrix-project requires special extraction. */ @CheckForNull public static <T extends Cause> T ghCauseFromRun(Run<?, ?> run, Class<T> tClass) { if (run instanceof MatrixRun) { MatrixBuild parentBuild = ((MatrixRun) run).getParentBuild(); if (nonNull(parentBuild)) { return parentBuild.getCause(tClass); } } else { return run.getCause(tClass); } return null; }
Example 9
Source File: GitLabBuildDescriptionRunListener.java From gitlab-plugin with GNU General Public License v2.0 | 5 votes |
@Override public void onStarted(Run<?, ?> build, TaskListener listener) { GitLabPushTrigger trigger = GitLabPushTrigger.getFromJob(build.getParent()); if (trigger != null && trigger.getSetBuildDescription()) { Cause cause = build.getCause(GitLabWebHookCause.class); if (cause != null && !cause.getShortDescription().isEmpty()) { try { build.setDescription(cause.getShortDescription()); } catch (IOException e) { listener.getLogger().println("Failed to set build description"); } } } }
Example 10
Source File: GitLabEnvironmentContributor.java From gitlab-plugin with GNU General Public License v2.0 | 5 votes |
@Override public void buildEnvironmentFor(@Nonnull Run r, @Nonnull EnvVars envs, @Nonnull TaskListener listener) throws IOException, InterruptedException { GitLabWebHookCause cause = null; if (r instanceof MatrixRun) { MatrixBuild parent = ((MatrixRun)r).getParentBuild(); if (parent != null) { cause = (GitLabWebHookCause) parent.getCause(GitLabWebHookCause.class); } } else { cause = (GitLabWebHookCause) r.getCause(GitLabWebHookCause.class); } if (cause != null) { envs.overrideAll(cause.getData().getBuildVariables()); } }
Example 11
Source File: BuildCulpritsRetriever.java From jenkins-build-monitor-plugin with MIT License | 5 votes |
public Set<String> getCommitters(Run<?, ?> run) { Set<String> committers = getCommittersForRun(run); //If no committers were found, recursively get upstream committers: if (committers.isEmpty()) { Cause.UpstreamCause upstreamCause = run.getCause(Cause.UpstreamCause.class); if (upstreamCause != null) { Run<?, ?> upstreamRun = upstreamCause.getUpstreamRun(); if (upstreamRun != null) { committers.addAll(getCommitters(upstreamRun)); } } } return committers; }
Example 12
Source File: JobRunnerForCause.java From github-integration-plugin with MIT License | 4 votes |
public synchronized int abortRunning(int number) throws IllegalAccessException { int aborted = 0; Computer[] computers = getJenkinsInstance().getComputers(); for (Computer computer : computers) { if (isNull(computer)) { continue; } List<Executor> executors = computer.getExecutors(); executors.addAll(computer.getOneOffExecutors()); for (Executor executor : executors) { if (isNull(executor) || !executor.isBusy() || nonNull(executor.getCauseOfDeath()) || !getInterruptCauses(executor).isEmpty() || getInterruptStatus(executor) == Result.ABORTED) { continue; } Queue.Executable executable = executor.getCurrentExecutable(); final SubTask parent = executable.getParent(); if (!(executable instanceof Run)) { continue; } final Run executableRun = (Run) executable; if (!(parent instanceof Job)) { continue; } final Job parentJob = (Job) parent; if (!parentJob.getFullName().equals(job.getFullName())) { // name doesn't match continue; } if (executableRun.getResult() == Result.ABORTED) { // was already aborted continue; } if (executableRun instanceof MatrixRun) { // the whole MatrixBuild will be aborted continue; } // if (executable instanceof MatrixBuild) { // final MatrixBuild executable1 = (MatrixBuild) executable; // executable1.doStop() // } final GitHubPRCause causeAction = (GitHubPRCause) executableRun.getCause(GitHubPRCause.class); if (nonNull(causeAction) && causeAction.getNumber() == number) { LOGGER.info("Aborting '{}', by interrupting '{}'", executableRun, executor); executor.interrupt(Result.ABORTED, new NewPRInterruptCause()); aborted++; } } } return aborted; }
Example 13
Source File: MergeRequestNotifier.java From gitlab-plugin with GNU General Public License v2.0 | 4 votes |
MergeRequest getMergeRequest(Run<?, ?> run) { GitLabWebHookCause cause = run.getCause(GitLabWebHookCause.class); return cause == null ? null : cause.getData().getMergeRequest(); }
Example 14
Source File: MergeRequestHookTriggerHandlerImpl.java From gitlab-plugin with GNU General Public License v2.0 | 4 votes |
private String getTargetBranchFromBuild(Run<?, ?> mergeBuild) { GitLabWebHookCause cause = mergeBuild.getCause(GitLabWebHookCause.class); return cause == null ? null : cause.getData().getTargetBranch(); }