Java Code Examples for hudson.model.Run#save()

The following examples show how to use hudson.model.Run#save() . 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: ResetQualityGateCommand.java    From warnings-ng-plugin with MIT License 5 votes vote down vote up
/**
 * Resets the quality gate for the specified analysis tool.
 *
 * @param selectedBuild
 *         the selected build that will show the action link
 * @param id
 *         the ID of the static analysis tool that should be reset
 */
@VisibleForTesting
public void resetReferenceBuild(final Run<?, ?> selectedBuild, final String id) {
    try {
        selectedBuild.addAction(new ResetReferenceAction(id));
        selectedBuild.save();
    }
    catch (IOException ignore) {
        // ignore
    }
}
 
Example 2
Source File: RunLoadCounter.java    From jenkins-test-harness with MIT License 5 votes vote down vote up
/**
 * Prepares a new project to be measured.
 * Usually called before starting builds, but may also be called retroactively.
 * @param project a project of any kind
 * @throws IOException if preparations fail
 */
public static void prepare(LazyBuildMixIn.LazyLoadingJob<?, ?> project) throws IOException {
    ExtensionList.lookup(RunListener.class).get(MarkerAdder.class).register((Job) project);
    for (Run<?, ?> build : project.getLazyBuildMixIn()._getRuns()) {
        Marker.add(build);
        build.save();
    }
}
 
Example 3
Source File: DockerFingerprintAction.java    From docker-commons-plugin with MIT License 5 votes vote down vote up
/**
 * Adds an action with a reference to fingerprint if required. It's
 * recommended to call the method from {
 *
 * @BulkChange} transaction to avoid saving the {@link Run} multiple times.
 * @param fp Fingerprint
 * @param imageId ID of the docker image
 * @param run Run to be updated
 * @throws IOException Cannot save the action
 */
static void addToRun(Fingerprint fp, String imageId, Run run) throws IOException {
    synchronized (run) {
        DockerFingerprintAction action = run.getAction(DockerFingerprintAction.class);
        if (action == null) {
            action = new DockerFingerprintAction();
            run.addAction(action);
        }
        
        if (action.imageIDs.add(imageId)) {
            run.save();
        } // else no need to save updates
    }
}
 
Example 4
Source File: DockerComposeBuild.java    From DotCi with MIT License 5 votes vote down vote up
private void addProcessedYamlToDotCiInfoAction(final Run run, final Map config) throws IOException {
    final DotCiBuildInfoAction dotCiBuildInfoAction = run.getAction(DotCiBuildInfoAction.class);
    if (dotCiBuildInfoAction == null) {
        run.addAction(new DotCiBuildInfoAction(new Yaml().dump(config)));
    } else {
        dotCiBuildInfoAction.setBuildConfiguration(new Yaml().dump(config));
    }
    run.save();
}
 
Example 5
Source File: ShellScriptRunner.java    From DotCi with MIT License 5 votes vote down vote up
private void addExecutionInfoAction(final Run run, final ShellCommands commands) throws IOException {
    final DotCiBuildInfoAction dotCiBuildInfoAction = run.getAction(DotCiBuildInfoAction.class);
    if (dotCiBuildInfoAction == null) {
        run.addAction(new DotCiBuildInfoAction(commands));
    } else {
        dotCiBuildInfoAction.addCommands(commands);
    }
    run.save();
}
 
Example 6
Source File: JiraSCMListener.java    From blueocean-plugin with MIT License 4 votes vote down vote up
@Override
public void onChangeLogParsed(Run<?, ?> run, SCM scm, TaskListener listener, ChangeLogSet<?> changelog) throws Exception {

    try {
        JiraSite jiraSite = JiraSite.get(run.getParent());
        if (jiraSite == null) {
            return;
        }
        Collection<String> issueKeys = getIssueKeys(changelog, jiraSite.getIssuePattern());

        if (issueKeys.isEmpty()) {
            return;
        }
        String jql = constructJQLQuery(issueKeys);
        JiraSession session = jiraSite.getSession();
        if (session == null) {
            return;
        }
        // Query for JIRA issues
        List<Issue> issues = session.getIssuesFromJqlSearch(jql);
        Set<JiraIssue> issuesFromJqlSearch = issues == null ? Collections.emptySet() :
            issues.stream().map( input -> new JiraIssue(input) )
                .collect( Collectors.toSet() );

        // If there are no JIRA issues, do not update the actions
        if (issuesFromJqlSearch.isEmpty()) {
            return;
        }
        // Create or update the JiraBuildAction
        JiraBuildAction action = run.getAction(JiraBuildAction.class);
        if (action == null) {
            run.addAction(new JiraBuildAction(run, issuesFromJqlSearch));
        } else {
            action.addIssues(issuesFromJqlSearch);
        }
        run.save();
    } catch (Exception e ){ // we do not want to fail the build if an issue happen here
        LOGGER.warn( "Failure executing Jira query to fetch issues. Skipping recording Jira issues.: {}", e.getMessage() );
        // stack trace in debug mode
        LOGGER.debug( e.getMessage(), e);
    }
}
 
Example 7
Source File: JUnitResultArchiver.java    From junit-plugin with MIT License 4 votes vote down vote up
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;
    }
}