@SuppressWarnings("rawtypes") @Override public AnnotatedLargeText getLogText() { return LogStorage.of(asFlowExecutionOwner()).overallLog(this, !isLogUpdated()); }
static @Nonnull LogStorage of(@Nonnull FlowExecutionOwner b) { try { for (LogStorageFactory factory : ExtensionList.lookup(LogStorageFactory.class)) { LogStorage storage = factory.forBuild(b); if (storage != null) { // Pending integration with JEP-207 / JEP-212, this choice is not persisted. return storage; } } // Similar to Run.getLogFile, but not supporting gzip: return FileLogStorage.forFile(new File(b.getRootDir(), "log")); } catch (Exception x) { return new BrokenLogStorage(x); } }
其中的这个方法也是过期的不推荐使用的. @Deprecated @Override public File getLogFile() { LOGGER.log(Level.WARNING, "Avoid calling getLogFile on " + this, new UnsupportedOperationException()); return LogStorage.of(asFlowExecutionOwner()).getLogFile(this, !isLogUpdated()); } /** * Provide a file containing the log text. * The default implementation creates a temporary file based on the current contents of {@link #overallLog}. * @param build as in {@link #overallLog} * @param complete as in {@link #overallLog} * @return a possibly temporary file * @deprecated Only used for compatibility with {@link Run#getLogFile}. */ @SuppressFBWarnings(value = "REC_CATCH_EXCEPTION", justification = "silly rule") @Deprecated default @Nonnull File getLogFile(@Nonnull FlowExecutionOwner.Executable build, boolean complete) { try { AnnotatedLargeText<FlowExecutionOwner.Executable> logText = overallLog(build, complete); FlowExecutionOwner owner = build.asFlowExecutionOwner(); File f = File.createTempFile("deprecated", ".log", owner != null ? owner.getRootDir() : null); f.deleteOnExit(); try (OutputStream os = new FileOutputStream(f)) { // Similar to Run#writeWholeLogTo but terminates even if !complete: long pos = 0; while (true) { long pos2 = logText.writeRawLogTo(pos, os); if (pos2 <= pos) { break; } pos = pos2; } } return f; } catch (Exception x) { Logger.getLogger(LogStorage.class.getName()).log(Level.WARNING, null, x); if (build instanceof Run) { return new File(((Run) build).getRootDir(), "log"); } else { return new File("broken.log"); // not much we can do } } }
在freestyle风格的job中点击 consoloe output 会调用到下面这个方法中 public @Nonnull AnnotatedLargeText getLogText() { return new AnnotatedLargeText(getLogFile(),getCharset(),!isLogUpdated(),this); }
/** * Returns the log file. * @return The file may reference both uncompressed or compressed logs * @deprecated Assumes file-based storage of the log, which is not necessarily the case for Pipelines after JEP-210. Use other methods giving various kinds of streams such as {@link Run#getLogReader()}, {@link Run#getLogInputStream()}, or {@link Run#getLogText()}. */ @Deprecated public @Nonnull File getLogFile() { File rawF = new File(getRootDir(), "log"); if (rawF.isFile()) { return rawF; } File gzF = new File(getRootDir(), "log.gz"); if (gzF.isFile()) { return gzF; } //If both fail, return the standard, uncompressed log file return rawF; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
综上来看,要么修改 workflow-job 插件, 要么修改 workflow-api 插件. 通过查找发现 有人已经提交了一个PR 在 workflow-api 插件中, https://github.com/jenkinsci/workflow-api-plugin/pull/95 其中有个bug描述 https://issues.jenkins-ci.org/browse/JENKINS-54678 其他重复的bug描述还有: JENKINS-55465 Empty console when properties compressBuildLog() is enabled JENKINS-54680 Compressed build logs not rendering with update to workflow-job plugin >= 2.26 JENKINS-55024 Pipeline Job Plugin (workflow-job-plugin) gives empty console output when an error occurs