Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 6 additions & 1 deletion core/src/main/resources/lib/layout/copyButton.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ 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">
Text to be copied into the clipboard.
Expand All @@ -43,11 +43,16 @@ THE SOFTWARE.
<st:attribute name="clazz">
Additional CSS class names
</st:attribute>
<st:attribute name="ref" use="required">
The id of the target element to be copied
@since TODO
</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)
Comment on lines 18 to +19
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR should have restructured the code to make this conditional on text being non-empty. It not doing that seems to have allowed #25976 to happen.

.then(() => {
// Show the completion message
hoverNotification(copyButton.getAttribute("message"), copyButton);
Expand Down