Display Console Output on the build page (behind an experimental flag) (#10115)

Co-authored-by: Tim Jacomb <21194782+timja@users.noreply.github.com>
This commit is contained in:
Jan FaracikandTim Jacomb authored and GitHub committed 2025-01-09 15:27:05 +00:00
1 parent b6e58331ed
commit 331c7685ca
13 files changed
+282 -82

No files matched your search

+10
View File
@@ -143,6 +143,7 @@ import java.util.HashSet;
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;
@@ -158,6 +159,7 @@ import java.util.logging.SimpleFormatter;
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;
@@ -1993,6 +1995,14 @@ public class Functions {
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,
@@ -83,11 +83,7 @@ public interface ConsoleUrlProvider extends Describable<ConsoleUrlProvider> {
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) {
@@ -105,8 +101,20 @@ public interface ConsoleUrlProvider extends Describable<ConsoleUrlProvider> {
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) {
@@ -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.";
}
}