本文整理了Java中hudson.model.TaskListener
类的一些代码示例,展示了TaskListener
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TaskListener
类的具体详情如下:
包路径:hudson.model.TaskListener
类名称:TaskListener
[英]Receives events that happen during some lengthy operation that has some chance of failures, such as a build, SCM change polling, slave launch, and so on.
This interface is implemented by Hudson core and passed to extension points so that they can record the progress of the operation without really knowing how those information and handled/stored by Hudson.
The information is one way or the other made available to users, and so the expectation is that when something goes wrong, enough information shall be written to a TaskListener so that the user can diagnose what's going wrong.
StreamTaskListener is the most typical implementation of this interface. All the TaskListener implementations passed to plugins from Hudson core are remotable.
[中]接收在长时间操作期间发生的事件,这些操作可能会失败,例如构建、SCM更改轮询、从机启动等。
该接口由Hudson core实现,并传递给扩展点,以便它们可以记录操作的进度,而不需要真正了解Hudson如何处理/存储这些信息。
这些信息是以某种方式提供给用户的,因此人们期望,当出现问题时,应向TaskListener写入足够的信息,以便用户能够诊断出问题所在。
StreamTaskListener是该接口最典型的实现。所有从Hudson core传递给插件的TaskListener实现都是远程的。
代码示例来源:origin: jenkinsci/jenkins
public FilePath performInstallation(ToolInstallation tool, Node node, TaskListener log) throws IOException, InterruptedException {
FilePath expected = preferredLocation(tool, node);
Installable inst = getInstallable();
if(inst==null) {
log.getLogger().println("Invalid tool ID "+id);
return expected;
}
if (inst instanceof NodeSpecific) {
inst = (Installable) ((NodeSpecific) inst).forNode(node, log);
}
if(isUpToDate(expected,inst))
return expected;
if(expected.installIfNecessaryFrom(new URL(inst.url), log, "Unpacking " + inst.url + " to " + expected + " on " + node.getDisplayName())) {
expected.child(".timestamp").delete(); // we don't use the timestamp
FilePath base = findPullUpDirectory(expected);
if(base!=null && base!=expected)
base.moveAllChildrenTo(expected);
// leave a record for the next up-to-date check
expected.child(".installedFrom").write(inst.url,"UTF-8");
expected.act(new ZipExtractionInstaller.ChmodRecAPlusX());
}
return expected;
}
代码示例来源:origin: jenkinsci/jenkins
@Override
public void perform(Run,?> build, FilePath workspace, Launcher launcher, TaskListener listener) throws InterruptedException {
try {
listener.getLogger().println(Messages.Fingerprinter_Recording());
Map
EnvVars envirOnment= build.getEnvironment(listener);
if(targets.length()!=0) {
String expandedTargets = environment.expand(targets);
record(build, workspace, listener, record, expandedTargets);
}
FingerprintAction fingerprintAction = build.getAction(FingerprintAction.class);
if (fingerprintAction != null) {
fingerprintAction.add(record);
} else {
build.addAction(new FingerprintAction(build,record));
}
if (enableFingerprintsInDependencyGraph) {
Jenkins.getInstance().rebuildDependencyGraphAsync();
}
} catch (IOException e) {
Functions.printStackTrace(e, listener.error(Messages.Fingerprinter_Failed()));
build.setResult(Result.FAILURE);
}
// failing to record fingerprints is an error but not fatal
}
代码示例来源:origin: jenkinsci/jenkins
@Override public PrintWriter fatalError(String msg) {
return delegate.fatalError(msg);
}
代码示例来源:origin: jenkinsci/jenkins
/**
* Places a {@link HyperlinkNote} on the given text.
*
* @param url
* If this starts with '/', it's interpreted as a path within the context path.
*/
default void hyperlink(String url, String text) throws IOException {
annotate(new HyperlinkNote(url, text.length()));
getLogger().print(text);
}
代码示例来源:origin: jenkinsci/jenkins
@Override
protected void fix(TaskListener listener) throws Exception {
LOGGER.info("Initiating a re-keying of secrets. See "+getLogFile());
SecretRewriter rewriter = new SecretRewriter();
try {
PrintStream log = listener.getLogger();
log.println("Started re-keying " + new Date());
int count = rewriter.rewriteRecursive(Jenkins.getInstance().getRootDir(), listener);
log.printf("Completed re-keying %d files on %s\n",count,new Date());
new RekeySecretAdminMonitor().done.on();
LOGGER.info("Secret re-keying completed");
} catch (Exception e) {
LOGGER.log(Level.SEVERE, "Fatal failure in re-keying secrets",e);
Functions.printStackTrace(e, listener.error("Fatal failure in rewriting secrets"));
}
}
代码示例来源:origin: jenkinsci/jenkins
listener.getLogger().println("Checking " + item.getFullDisplayName());
for (Node node : nodes) {
FilePath ws = node.getWorkspaceFor(item);
if (ws == null) {
continue; // offline, fine
check = shouldBeDeleted(item, ws, node);
} catch (IOException x) {
Functions.printStackTrace(x, listener.error("Failed to check " + node.getDisplayName()));
continue;
} catch (InterruptedException x) {
Functions.printStackTrace(x, listener.error("Failed to check " + node.getDisplayName()));
continue;
listener.getLogger().println("Deleting " + ws + " on " + node.getDisplayName());
try {
ws.deleteRecursive();
WorkspaceList.tempDir(ws).deleteRecursive();
} catch (IOException x) {
Functions.printStackTrace(x, listener.error("Failed to delete " + ws + " on " + node.getDisplayName()));
} catch (InterruptedException x) {
Functions.printStackTrace(x, listener.error("Failed to delete " + ws + " on " + node.getDisplayName()));
代码示例来源:origin: org.jenkins-ci.plugins/javadoc
@Override public void perform(Run,?> build, FilePath workspace, Launcher launcher, TaskListener listener) throws InterruptedException, IOException {
listener.getLogger().println(Messages.JavadocArchiver_Publishing());
EnvVars env = build.getEnvironment(listener);
FilePath javadoc = workspace.child(env.expand(javadocDir));
FilePath target = new FilePath(keepAll ? getJavadocDir(build) : getJavadocDir(build.getParent()));
try {
if (javadoc.copyRecursiveTo("**/*",target)==0) {
if(build.getResult().isBetterOrEqualTo(Result.UNSTABLE)) {
// If the build failed, don't complain that there was no javadoc.
// The build probably didn't even get to the point where it produces javadoc.
listener.error(Messages.JavadocArchiver_NoMatchFound(javadoc,javadoc.validateAntFileMask("**/*")));
}
build.setResult(Result.FAILURE);
return;
}
} catch (IOException e) {
Util.displayIOException(e,listener);
e.printStackTrace(listener.fatalError(Messages.JavadocArchiver_UnableToCopy(javadoc,target)));
build.setResult(Result.FAILURE);
return;
}
build.addAction(new JavadocBuildAction());
}
代码示例来源:origin: jenkinsci/jenkins
private boolean installIfNecessaryFrom(@Nonnull URL archive, @CheckForNull TaskListener listener, @Nonnull String message, int maxRedirects) throws InterruptedException, IOException {
try {
FilePath timestamp = this.child(".timestamp");
long lastModified = timestamp.lastModified();
URLConnection con;
try {
if (this.exists()) {
listener.getLogger().println("Skipping installation of " + archive + " to " + remote + ": " + x);
listener.getLogger().println("Following redirect " + archive.toExternalForm() + " -> " + location);
return installIfNecessaryFrom(getUrlFactory().newURL(location), listener, message, maxRedirects - 1);
} else {
listener.getLogger().println("Skipping installation of " + archive + " to " + remote + " due to too many redirects.");
return false;
return false;
} else if (responseCode != HttpURLConnection.HTTP_OK) {
listener.getLogger().println("Skipping installation of " + archive + " to " + remote + " due to server error: " + responseCode + " " + httpCon.getResponseMessage());
return false;
listener.getLogger().println(message);
if (isRemote()) {
} catch (IOException x) {
if (listener != null) {
Functions.printStackTrace(x, listener.error("Failed to download " + archive + " from agent; will retry from master"));
代码示例来源:origin: jenkinsci/docker-slaves-plugin
@Override
public void pullImage(TaskListener listener, String image) throws IOException, InterruptedException {
ArgumentListBuilder args = new ArgumentListBuilder()
.add("pull")
.add(image);
Launcher launcher = new Launcher.LocalLauncher(listener);
int status = launchDockerCLI(launcher, args)
.stdout(launcher.getListener().getLogger()).join();
if (status != 0) {
throw new IOException("Failed to pull image " + image);
}
}
代码示例来源:origin: jenkinsci/jenkins
private boolean shouldTrigger(Run upstreamBuild, TaskListener listener) {
Jenkins jenkins = Jenkins.getInstance();
if (job == null) {
return false;
downstreamVisible = jenkins.getItemByFullName(job.getFullName()) == job;
} catch (AccessDeniedException ex) {
Authentication originalAuth = Jenkins.getAuthentication();
Job upstream = upstreamBuild.getParent();
Authentication auth = Tasks.getAuthenticationOf((Queue.Task) job);
Item authUpstream = null;
try {
authUpstream = jenkins.getItemByFullName(upstream.getFullName());
if (downstreamVisible) {
listener.getLogger().println(Messages.ReverseBuildTrigger_running_as_cannot_even_see_for_trigger_f(auth.getName(),
upstream.getFullName(), job.getFullName()));
} else {
LOGGER.log(Level.WARNING, "Running as {0} cannot even {1} {2} for trigger from {3}, (but cannot tell {4} that)",
Result result = upstreamBuild.getResult();
return result != null && result.isBetterOrEqualTo(threshold);
代码示例来源:origin: io.jenkins.plugins/docker-slaves
Jenkins j = Jenkins.getInstance();
if (j != null) {
COMPUTERS: for (Computer c : j.getComputers()) {
for (Executor e : c.getExecutors()) {
Queue.Executable exec = e.getCurrentExecutable();
listener.getLogger().println("Queue item for node block in " + run.getFullDisplayName() + " is missing (perhaps JENKINS-34281), but cannot reschedule");
return;
listener.getLogger().println("Queue item for node block in " + run.getFullDisplayName() + " is missing (perhaps JENKINS-34281); rescheduling");
try {
start();
代码示例来源:origin: org.jenkins-ci.plugins/git
@Override
protected void perform(final TaskListener listener) throws Exception {
final EnvVars envirOnment= getRun().getEnvironment(listener);
final FilePath workspace = new FilePath(new File(ws));
final GitClient git = Git.with(listener, environment)
.in(workspace)
.getClient();
for (Map.Entry
try {
String buildNum = "jenkins-"
+ getRun().getParent().getName().replace(" ", "_")
+ "-" + entry.getValue();
git.tag(entry.getValue(), "Jenkins Build #" + buildNum);
for (Map.Entry
GitTagAction.this.tags.get(e.getKey()).add(e.getValue());
getRun().save();
workerThread = null;
}
catch (GitException ex) {
ex.printStackTrace(listener.error("Error tagging repo '%s' : %s", entry.getKey(), ex.getMessage()));
// Failed. Try the next one
listener.getLogger().println("Trying next branch");
}
}
}
}
代码示例来源:origin: jenkinsci/docker-custom-build-environment-plugin
@Override
public String prepareDockerImage(Docker docker, AbstractBuild build, TaskListener listener, boolean forcePull, boolean noCache) throws IOException, InterruptedException {
String expandedCOntextPath= build.getEnvironment(listener).expand(contextPath);
FilePath filePath = build.getWorkspace().child(expandedContextPath);
FilePath dockerFile = filePath.child(getDockerfile());
if (!dockerFile.exists()) {
listener.getLogger().println("Your project is missing a Dockerfile");
throw new InterruptedException("Your project is missing a Dockerfile");
}
listener.getLogger().println("Build Docker image from " + expandedContextPath + "/"+getDockerfile()+" ...");
return docker.buildImage(filePath, dockerFile.getRemote(), forcePull, noCache);
}
代码示例来源:origin: jenkinsci/jenkins
Result result = build.getResult();
if (onlyIfSuccessful && result != null && result.isWorseThan(Result.UNSTABLE)) {
listener.getLogger().println(Messages.ArtifactArchiver_SkipBecauseOnlyIfSuccessful());
return;
listener.getLogger().println(Messages.ArtifactArchiver_ARCHIVING_ARTIFACTS());
try {
String artifacts = build.getEnvironment(listener).expand(this.artifacts);
Map
if (!files.isEmpty()) {
build.pickArtifactManager().archive(ws, launcher, BuildListenerAdapter.wrap(listener), files);
if (fingerprint) {
new Fingerprinter(artifacts).perform(build, ws, launcher, listener);
if (result == null || result.isBetterOrEqualTo(Result.UNSTABLE)) {
try {
String msg = ws.validateAntFileMask(artifacts, FilePath.VALIDATE_ANT_FILE_MASK_BOUND, caseSensitive);
if (msg != null) {
listener.getLogger().println(msg);
Functions.printStackTrace(e, listener.getLogger());
listener.getLogger().println(Messages.ArtifactArchiver_NoMatchFound(artifacts));
} else {
throw new AbortException(Messages.ArtifactArchiver_NoMatchFound(artifacts));
代码示例来源:origin: jenkinsci/artifactory-plugin
@Override
protected Boolean run() throws Exception {
ArgumentListBuilder args = new ArgumentListBuilder();
org.jfrog.hudson.ArtifactoryServer artifactoryServer = Utils.prepareArtifactoryServer(null, step.getServer());
ArtifactoryConfigurator cOnfigurator= new ArtifactoryConfigurator(artifactoryServer);
CredentialsConfig deployerCOnfig= CredentialManager.getPreferredDeployer(configurator, artifactoryServer);
String username = deployerConfig.provideUsername(build.getParent());
String serverName = step.getServerName();
args.addTokenized("conan user");
args.add(username);
args.add("-p");
args.addMasked(deployerConfig.providePassword(build.getParent()));
args.add("-r");
args.add(serverName);
EnvVars extendedEnv = new EnvVars(env);
extendedEnv.put(Utils.CONAN_USER_HOME, step.getConanHome());
listener.getLogger().println("Adding conan user '" + username + "', server '" + serverName + "'");
Utils.exeConan(args, ws, launcher, listener, build, extendedEnv);
return true;
}
}
代码示例来源:origin: jenkinsci/artifactory-plugin
private ArgumentListBuilder getGradleExecutor() {
ArgumentListBuilder args = new ArgumentListBuilder();
if (gradleBuild.isUseWrapper()) {
String execName = launcher.isUnix() ? GradleInstallation.UNIX_GRADLE_WRAPPER_COMMAND : GradleInstallation.WINDOWS_GRADLE_WRAPPER_COMMAND;
FilePath gradleWrapperFile = new FilePath(new FilePath(ws, rootDir), execName);
args.add(gradleWrapperFile.getRemote());
} else {
try {
args.add(getGradleExe());
} catch (Exception e) {
listener.error("Couldn't find Gradle executable.");
build.setResult(Result.FAILURE);
throw new Run.RunnerAbortedException();
}
}
args.addTokenized(getSwitches()).
addTokenized(tasks).
add("-b", getBuildFileFullPath());
if (!launcher.isUnix()) {
args = args.toWindowsCommand();
}
return args;
}
代码示例来源:origin: jenkinsci/jenkins
public String getToolHome(Node node, ToolInstallation tool, TaskListener log) throws IOException, InterruptedException {
if (node.getRootPath() == null) {
log.error(node.getDisplayName() + " is offline; cannot locate " + tool.getName());
return null;
return installer.performInstallation(tool, node, log).getRemote();
} finally {
semaphore.release();
installer.getDescriptor().getDisplayName(),
tool.getName(),
node.getDisplayName()));
log.getLogger().println(message);
代码示例来源:origin: jenkinsci/jenkins
/**
* Sends the stdout to the given {@link TaskListener}.
*
* @param out Task listener (must be safely remotable)
* @return {@code this}
*/
public ProcStarter stdout(@Nonnull TaskListener out) {
stdout = out.getLogger();
stdoutListener = out;
return this;
}
代码示例来源:origin: jenkinsci/subversion-plugin
private void assertRevision(@CheckForNull SCMRevision rev, @CheckForNull String expectedFile, @NonNull SCMSource source, @NonNull Run,?> run, @NonNull TaskListener listener) throws Exception {
if (rev == null) {
assertNull(expectedFile);
return;
}
FilePath ws = new FilePath(run.getRootDir()).child("tmp");
try {
source.build(rev.getHead(), rev).checkout(run, new Launcher.LocalLauncher(listener), ws, listener, null, SCMRevisionState.NONE);
} catch (Exception x) {
x.printStackTrace(listener.error("could not check out"));
assertNull(expectedFile);
return;
}
FilePath file = ws.child("file");
assertEquals(expectedFile, file.exists() ? file.readToString() : null);
}
代码示例来源:origin: jenkinsci/jenkins
@Override
public boolean shouldTriggerBuild(AbstractBuild build, TaskListener listener,
List
AbstractProject downstream = getDownstreamProject();
if (Jenkins.getInstance().getItemByFullName(downstream.getFullName()) != downstream) { // this checks Item.READ also on parent folders
LOGGER.log(Level.WARNING, "Running as {0} cannot even see {1} for trigger from {2}", new Object[] {Jenkins.getAuthentication().getName(), downstream, getUpstreamProject()});
return false; // do not even issue a warning to build log
}
if (!downstream.hasPermission(Item.BUILD)) {
listener.getLogger().println(Messages.BuildTrigger_you_have_no_permission_to_build_(ModelHyperlinkNote.encodeTo(downstream)));
return false;
}
return build.getResult().isBetterOrEqualTo(threshold);
}
});