下面列出了hudson.model.Run#save ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* 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
}
}
/**
* 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();
}
}
/**
* 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
}
}
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();
}
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();
}
@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);
}
}
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;
}
}