Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add copy-to-clipboard button to the build console output #8960

Merged
merged 6 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions core/src/main/resources/hudson/model/Run/console.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ THE SOFTWARE.
<st:include page="sidepanel.jelly" />
<l:breadcrumb title="${%Console Output}" />
<l:main-panel>
<t:buildCaption>${%Console Output}</t:buildCaption>
<t:buildCaption>
${%Console Output}
<l:copyButton message="${%successfullyCopied}" tooltip="${%clickToCopy}" ref="out"/>
</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}" />
Expand All @@ -60,7 +63,7 @@ THE SOFTWARE.
</j:when>
<!-- output is completed now. -->
<j:otherwise>
<pre class="console-output">
<pre class="console-output" id="out">
<st:getOutput var="output" />
<j:whitespace>${it.writeLogTo(offset,output)}</j:whitespace>
</pre>
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/resources/hudson/model/Run/console.properties
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@
# THE SOFTWARE.

skipSome=Skipping {0,number,integer} KB.. <a href="{1}">Full Log</a>
clickToCopy=Click to copy
successfullyCopied=Copied to clipboard
8 changes: 6 additions & 2 deletions core/src/main/resources/lib/layout/copyButton.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ THE SOFTWARE.
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:i="jelly:fmt" xmlns:x="jelly:xml">
<st:documentation>
Button that copies text into the user's clipboard upon click
Button that copies text into the user's clipboard upon click, either <code>text</code> or <code>ref</code> is required.

<st:attribute name="text" use="required">
anhcraft marked this conversation as resolved.
Show resolved Hide resolved
<st:attribute name="text">
Text to be copied into the clipboard.
</st:attribute>
<st:attribute name="message">
Expand All @@ -43,11 +43,15 @@ THE SOFTWARE.
<st:attribute name="clazz">
Additional CSS class names
</st:attribute>
<st:attribute name="ref">
The id of the target element to be copied
anhcraft marked this conversation as resolved.
Show resolved Hide resolved
</st:attribute>
</st:documentation>

<!-- 'copy-button' class is for backwards compatability -->
<button class="copy-button jenkins-button ${attrs.iconOnly == 'true' ? 'jenkins-button--tertiary' : ''} jenkins-copy-button ${attrs.clazz}"
text="${attrs.text}"
ref="${attrs.ref}"
message="${attrs.message ?: '%Copied'}"
tooltip="${attrs.tooltip ?: '%Copy'}"
type="button">
Expand Down
11 changes: 10 additions & 1 deletion core/src/main/resources/lib/layout/copyButton/copyButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,18 @@ Behaviour.specify(
function (copyButton) {
copyButton.addEventListener("click", () => {
if (isSecureContext) {
var text = copyButton.getAttribute("text");
if (copyButton.hasAttribute("ref")) {
var ref = copyButton.getAttribute("ref");
var target = document.getElementById(ref);
if (target) {
text = target.innerText;
}
}

// Copy the text to the clipboard
navigator.clipboard
.writeText(copyButton.getAttribute("text"))
.writeText(text)
.then(() => {
// Show the completion message
hoverNotification(copyButton.getAttribute("message"), copyButton);
Expand Down
Loading