Skip to content

Commit

Permalink
Display Console Output on the build page (behind an experimental flag) (
Browse files Browse the repository at this point in the history
jenkinsci#10115)

Co-authored-by: Tim Jacomb <21194782+timja@users.noreply.github.com>
  • Loading branch information
janfaracik and timja authored Jan 9, 2025
1 parent b6e5833 commit 331c768
Show file tree
Hide file tree
Showing 13 changed files with 282 additions and 82 deletions.
10 changes: 10 additions & 0 deletions core/src/main/java/hudson/Functions.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.SortedMap;
import java.util.TimeZone;
Expand All @@ -158,6 +159,7 @@
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import jenkins.console.ConsoleUrlProvider;
import jenkins.console.DefaultConsoleUrlProvider;
import jenkins.console.WithConsoleUrl;
import jenkins.model.GlobalConfiguration;
import jenkins.model.GlobalConfigurationCategory;
Expand Down Expand Up @@ -1993,6 +1995,14 @@ public static String joinPath(String... components) {
return consoleUrl != null ? Stapler.getCurrentRequest().getContextPath() + '/' + consoleUrl : null;
}

/**
* @param run the run
* @return the Console Provider for the given run, if null, the default Console Provider
*/
public static ConsoleUrlProvider getConsoleProviderFor(Run<?, ?> run) {
return Optional.ofNullable(ConsoleUrlProvider.getProvider(run)).orElse(new DefaultConsoleUrlProvider());
}

/**
* Escapes the character unsafe for e-mail address.
* See <a href="https://en.wikipedia.org/wiki/Email_address">the Wikipedia page</a> for the details,
Expand Down
20 changes: 14 additions & 6 deletions core/src/main/java/jenkins/console/ConsoleUrlProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,7 @@ default Descriptor<ConsoleUrlProvider> getDescriptor() {
return Stapler.getCurrentRequest().getContextPath() + '/' + run.getConsoleUrl();
}

/**
* Looks up the {@link #getConsoleUrl} value from the first provider to offer one.
* @since 2.476
*/
static @NonNull String consoleUrlOf(Run<?, ?> run) {
static List<ConsoleUrlProvider> all() {
final List<ConsoleUrlProvider> providers = new ArrayList<>();
User currentUser = User.current();
if (currentUser != null) {
Expand All @@ -105,8 +101,20 @@ default Descriptor<ConsoleUrlProvider> getDescriptor() {
if (globalProviders != null) {
providers.addAll(globalProviders);
}
return providers;
}

static ConsoleUrlProvider getProvider(Run<?, ?> run) {
return all().stream().filter(provider -> provider.getConsoleUrl(run) != null).findFirst().orElse(null);
}

/**
* Looks up the {@link #getConsoleUrl} value from the first provider to offer one.
* @since 2.476
*/
static @NonNull String consoleUrlOf(Run<?, ?> run) {
String url = null;
for (ConsoleUrlProvider provider : providers) {
for (ConsoleUrlProvider provider : all()) {
try {
String tempUrl = provider.getConsoleUrl(run);
if (tempUrl != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* The MIT License
*
* Copyright (c) 2025, Jan Faracik
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package jenkins.model.experimentalflags;

import edu.umd.cs.findbugs.annotations.Nullable;
import hudson.Extension;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;

@Extension
@Restricted(NoExternalUse.class)
public class NewBuildPageUserExperimentalFlag extends BooleanUserExperimentalFlag {
public NewBuildPageUserExperimentalFlag() {
super("new-build-page.flag");
}

@Override
public String getDisplayName() {
return "New build page";
}

@Nullable
@Override
public String getShortDescription() {
return "Enables a revamped build page. This feature is still a work in progress, so some things might not work perfectly yet.";
}
}
38 changes: 38 additions & 0 deletions core/src/main/resources/hudson/model/Run/console-log.jelly
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:l="/lib/layout" xmlns:t="/lib/hudson">
<j:set var="threshold" value="${h.getSystemProperty('hudson.consoleTailKB')?:'150'}" />
<!-- Show at most last 150KB (can override with system property) unless consoleFull is set -->
<j:set var="offset" value="${empty(consoleFull) ? it.logText.length()-threshold*1024 : 0}" />
<j:choose>
<j:when test="${offset > 0}">
<a class="jenkins-button jenkins-!-accent-color jenkins-!-padding-2 jenkins-!-margin-bottom-2" style="width: 100%; justify-content: start" href="consoleFull">
<l:icon src="symbol-help-circle" />
${%skipSome(offset / 1024)}
</a>
</j:when>
<j:otherwise>
<j:set var="offset" value="${0}" />
</j:otherwise>
</j:choose>

<j:out value="${h.generateConsoleAnnotationScriptAndStylesheet()}"/>

<j:choose>
<!-- Do progressive console output -->
<j:when test="${it.isLogUpdated()}">
<pre id="out" class="console-output" />
<div id="spinner">
<l:progressAnimation/>
</div>
<t:progressiveText href="logText/progressiveHtml" idref="out" spinner="spinner"
startOffset="${offset}" onFinishEvent="jenkins:consoleFinished"/>
</j:when>
<!-- output is completed now. -->
<j:otherwise>
<pre class="console-output">
<st:getOutput var="output" />
<j:whitespace>${it.writeLogTo(offset,output)}</j:whitespace>
</pre>
</j:otherwise>
</j:choose>
</j:jelly>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
skipSome=This log is too long to show here, {0,number,integer} KB has been skipped — click to see the complete log
33 changes: 1 addition & 32 deletions core/src/main/resources/hudson/model/Run/console.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -50,38 +50,7 @@ THE SOFTWARE.
${%Console Output}
</t:buildCaption>

<j:set var="threshold" value="${h.getSystemProperty('hudson.consoleTailKB')?:'150'}" />
<!-- Show at most last 150KB (can override with system property) unless consoleFull is set -->
<j:set var="offset" value="${empty(consoleFull) ? it.logText.length()-threshold*1024 : 0}" />
<j:choose>
<j:when test="${offset > 0}">
${%skipSome(offset/1024,"consoleFull")}
</j:when>
<j:otherwise>
<j:set var="offset" value="${0}" />
</j:otherwise>
</j:choose>

<j:out value="${h.generateConsoleAnnotationScriptAndStylesheet()}"/>

<j:choose>
<!-- Do progressive console output -->
<j:when test="${it.isLogUpdated()}">
<pre id="out" class="console-output" />
<div id="spinner">
<l:progressAnimation/>
</div>
<t:progressiveText href="logText/progressiveHtml" idref="out" spinner="spinner"
startOffset="${offset}" onFinishEvent="jenkins:consoleFinished"/>
</j:when>
<!-- output is completed now. -->
<j:otherwise>
<pre class="console-output" id="out">
<st:getOutput var="output" />
<j:whitespace>${it.writeLogTo(offset,output)}</j:whitespace>
</pre>
</j:otherwise>
</j:choose>
<st:include page="console-log.jelly" />
</l:main-panel>
</l:layout>
</j:jelly>
89 changes: 49 additions & 40 deletions core/src/main/resources/hudson/model/Run/index.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -25,53 +25,62 @@ THE SOFTWARE.

<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:i="jelly:fmt">
<l:layout title="${it.fullDisplayName}">
<st:include page="sidepanel.jelly" />
<l:userExperimentalFlag var="newBuildPage" flagClassName="jenkins.model.experimentalflags.NewBuildPageUserExperimentalFlag" />

<!-- no need for additional breadcrumb here as we're on an index page already including breadcrumb -->
<l:main-panel>
<j:set var="controls">
<t:editDescriptionButton permission="${it.UPDATE}"/>
<l:hasPermission permission="${it.UPDATE}">
<st:include page="logKeep.jelly" />
</l:hasPermission>
</j:set>
<j:choose>
<j:when test="${newBuildPage}">
<st:include page="new-build-page.jelly" />
</j:when>
<j:otherwise>
<l:layout title="${it.fullDisplayName}">
<st:include page="sidepanel.jelly" />

<t:buildCaption controls="${controls}">${it.displayName} (<i:formatDate value="${it.timestamp.time}" type="both" dateStyle="medium" timeStyle="medium"/>)</t:buildCaption>
<!-- no need for additional breadcrumb here as we're on an index page already including breadcrumb -->
<l:main-panel>
<j:set var="controls">
<t:editDescriptionButton permission="${it.UPDATE}"/>
<l:hasPermission permission="${it.UPDATE}">
<st:include page="logKeep.jelly" />
</l:hasPermission>
</j:set>

<div>
<t:editableDescription permission="${it.UPDATE}" hideButton="true"/>
</div>
<t:buildCaption controls="${controls}">${it.displayName} (<i:formatDate value="${it.timestamp.time}" type="both" dateStyle="medium" timeStyle="medium"/>)</t:buildCaption>

<div style="float:right; z-index: 1; position:relative; margin-left: 1em">
<div style="margin-top:1em">
${%startedAgo(it.timestampString)}
</div>
<div>
<j:if test="${it.building}">
${%beingExecuted(it.executor.timestampString)}
</j:if>
<j:if test="${!it.building}">
${%Took} <a href="${rootURL}/${it.parent.url}buildTimeTrend">${it.durationString}</a>
</j:if>
<st:include page="details.jelly" optional="true" />
</div>
</div>
<div>
<t:editableDescription permission="${it.UPDATE}" hideButton="true"/>
</div>

<div style="float:right; z-index: 1; position:relative; margin-left: 1em">
<div style="margin-top:1em">
${%startedAgo(it.timestampString)}
</div>
<div>
<j:if test="${it.building}">
${%beingExecuted(it.executor.timestampString)}
</j:if>
<j:if test="${!it.building}">
${%Took} <a href="${rootURL}/${it.parent.url}buildTimeTrend">${it.durationString}</a>
</j:if>
<st:include page="details.jelly" optional="true" />
</div>
</div>

<table>
<t:artifactList build="${it}" caption="${%Build Artifacts}"
permission="${it.ARTIFACTS}" />

<!-- give actions a chance to contribute summary item -->
<j:forEach var="a" items="${it.allActions}">
<st:include page="summary.jelly" from="${a}" optional="true" it="${a}" />
</j:forEach>
<table>
<t:artifactList build="${it}" caption="${%Build Artifacts}"
permission="${it.ARTIFACTS}" />

<st:include page="summary.jelly" optional="true" />
</table>
<!-- give actions a chance to contribute summary item -->
<j:forEach var="a" items="${it.allActions}">
<st:include page="summary.jelly" from="${a}" optional="true" it="${a}" />
</j:forEach>

<st:include page="main.jelly" optional="true" />
</l:main-panel>
</l:layout>
<st:include page="summary.jelly" optional="true" />
</table>

<st:include page="main.jelly" optional="true" />
</l:main-panel>
</l:layout>
</j:otherwise>
</j:choose>
</j:jelly>
78 changes: 78 additions & 0 deletions core/src/main/resources/hudson/model/Run/new-build-page.jelly
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<!--
The MIT License
Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi, Matthew R. Harrah,
Tom Huybrechts, id:cactusman, Romain Seguy
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->

<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:i="jelly:fmt">
<l:layout title="${it.fullDisplayName}">
<st:include page="sidepanel.jelly" />

<!-- no need for additional breadcrumb here as we're on an index page already including breadcrumb -->
<l:main-panel>
<j:set var="controls">
<t:editDescriptionButton permission="${it.UPDATE}"/>
<l:hasPermission permission="${it.UPDATE}">
<st:include page="logKeep.jelly" />
</l:hasPermission>
</j:set>

<t:buildCaption controls="${controls}">${it.displayName} (<i:formatDate value="${it.timestamp.time}" type="both" dateStyle="medium" timeStyle="medium"/>)</t:buildCaption>

<div>
<t:editableDescription permission="${it.UPDATE}" hideButton="true"/>
</div>

<st:include page="console.jelly" from="${h.getConsoleProviderFor(it)}" optional="true" />

<div style="float:right; z-index: 1; position:relative; margin-left: 1em">
<div style="margin-top:1em">
${%startedAgo(it.timestampString)}
</div>
<div>
<j:if test="${it.building}">
${%beingExecuted(it.executor.timestampString)}
</j:if>
<j:if test="${!it.building}">
${%Took} <a href="${rootURL}/${it.parent.url}buildTimeTrend">${it.durationString}</a>
</j:if>
<st:include page="details.jelly" optional="true" />
</div>
</div>

<table>
<t:artifactList build="${it}" caption="${%Build Artifacts}"
permission="${it.ARTIFACTS}" />

<!-- give actions a chance to contribute summary item -->
<j:forEach var="a" items="${it.allActions}">
<st:include page="summary.jelly" from="${a}" optional="true" it="${a}" />
</j:forEach>

<st:include page="summary.jelly" optional="true" />
</table>

<st:include page="main.jelly" optional="true" />
</l:main-panel>
</l:layout>
</j:jelly>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
startedAgo=Started {0} ago
beingExecuted=Build has been executing for {0}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:l="/lib/layout">
<j:set var="controls">
<a href="consoleText" download="${it.displayName}.txt" tooltip="${%Download}" class="jenkins-card__reveal">
<l:icon src="symbol-download" />
</a>
</j:set>

<l:card title="${%Console Output}" expandable="console" controls="${controls}">
<div class="app-console-output-widget progressive-text-container">
<st:include page="console-log.jelly" />
</div>
</l:card>
</j:jelly>
Loading

0 comments on commit 331c768

Please sign in to comment.