Skip to content

Commit 3355fc8

Browse files
janfaraciktimja
andauthored
Adapt Script Console for experimental Manage Jenkins UI (#11333)
Co-authored-by: Tim Jacomb <timjacomb1@gmail.com> Co-authored-by: Tim Jacomb <21194782+timja@users.noreply.github.com>
1 parent a8ef705 commit 3355fc8

File tree

5 files changed

+98
-51
lines changed

5 files changed

+98
-51
lines changed

core/src/main/resources/hudson/model/Computer/_script.jelly

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,11 @@ THE SOFTWARE.
2727
-->
2828
<?jelly escape-by-default='true'?>
2929
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
30-
<t:scriptConsole>
31-
<pre>println System.getenv("PATH")</pre>
32-
<pre>println "uname -a".execute().text</pre>
33-
<p>
30+
<j:set var="script" value='println System.getenv("PATH")' />
31+
<j:set var="script2" value='println "uname -a".execute().text' />
32+
33+
<t:scriptConsole scripts="${[script, script2]}">
34+
<p class="jenkins-section__description">
3435
${%This execution happens in the agent JVM.}
3536
</p>
3637
</t:scriptConsole>

core/src/main/resources/jenkins/model/Jenkins/_script.jelly

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,12 @@ THE SOFTWARE.
2727
-->
2828
<?jelly escape-by-default='true'?>
2929
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
30-
<t:scriptConsole layout="one-column">
31-
<pre>println(Jenkins.instance.pluginManager.plugins)</pre>
32-
</t:scriptConsole>
33-
</j:jelly>
30+
<j:new var="managementLink" className="jenkins.management.ConsoleLink" />
31+
32+
<l:settings-subpage includeBreadcrumb="true" permission="${app.ADMINISTER}"
33+
header="${null}" noDefer="true" managementLink="${managementLink}">
34+
35+
<t:scriptConsole scripts="${['println(Jenkins.instance.pluginManager.plugins)']}"
36+
layout="none" />
37+
</l:settings-subpage>
38+
</j:jelly>

core/src/main/resources/lib/hudson/scriptConsole.jelly

Lines changed: 80 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -26,56 +26,101 @@ THE SOFTWARE.
2626
Called from doScript() to display the execution result and the form.
2727
-->
2828
<?jelly escape-by-default='true'?>
29-
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:f="/lib/form">
29+
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout"
30+
xmlns:f="/lib/form" xmlns:t="/lib/hudson" xmlns:local="local">
3031
<st:documentation>
3132
<st:attribute name="layout" use="optional">
32-
Specify which layout to be use for the page.
33+
Specify which layout to be used for the page.
3334
See the type in layout for more details.
35+
Script console also supports `none`, which removes the traditional layout frame.
3436
By default, it is `two-column`.
3537
</st:attribute>
38+
<st:attribute name="scripts" use="optional">
39+
Displays executable example scripts.
40+
</st:attribute>
3641
</st:documentation>
3742

38-
<j:set var="layout" value="${attrs.layout != null ? attrs.layout : 'two-column'}" />
39-
<l:layout permission="${app.ADMINISTER}" title="${%scriptConsole}" type="${layout}">
40-
<j:if test="${layout == 'two-column'}">
41-
<st:include page="sidepanel.jelly" />
42-
</j:if>
43+
<d:taglib uri="local">
44+
<d:tag name="contents">
45+
<l:app-bar title="${%scriptConsole}">
46+
<t:help href="https://www.jenkins.io/redirect/script-console" />
47+
</l:app-bar>
4348

44-
<l:breadcrumb title="${%scriptConsole}"/>
45-
<l:main-panel>
46-
<h1>${%scriptConsole}</h1>
49+
<p class="jenkins-page-description">
50+
${%description}
51+
</p>
4752

4853
<j:choose>
4954
<j:when test="${it.channel != null}">
50-
<p>
51-
${%description}
52-
</p>
53-
<!-- this is where the example goes -->
54-
<d:invokeBody />
55-
<p>
56-
${%description2}
57-
</p>
55+
<f:section title="${%Getting started}">
56+
<p class="jenkins-section__description">
57+
${%instructions}
58+
</p>
59+
60+
<j:forEach var="script" items="${scripts}">
61+
<form action="script" method="post">
62+
<div class="jenkins-quote jenkins-quote--monospace jenkins-!-margin-bottom-5">
63+
${script}
64+
<input type="hidden"
65+
name="script"
66+
value="${script}" />
67+
<button class="jenkins-button jenkins-button--tertiary jenkins-!-build-color"
68+
tooltip="${%Run example}">
69+
<l:icon src="symbol-play" />
70+
</button>
71+
</div>
72+
</form>
73+
</j:forEach>
74+
75+
<!-- this is where the example goes -->
76+
<d:invokeBody />
77+
</f:section>
5878

59-
<form action="script" method="post">
60-
<textarea id="script" name="script" class="script">${request2.getParameter('script')}</textarea>
61-
<div align="right">
62-
<f:submit value="${%Run}"/>
63-
</div>
64-
</form>
65-
<st:adjunct includes="org.kohsuke.stapler.codemirror.mode.groovy.groovy"/>
66-
<st:adjunct includes="org.kohsuke.stapler.codemirror.theme.default"/>
67-
<j:if test="${output!=null}">
68-
<h2>
69-
${%Result}
70-
<l:copyButton message="${%successfullyCopied}" tooltip="${%clickToCopy}" text="${output}"/>
71-
</h2>
72-
<pre><st:out value="${output}"/></pre>
73-
</j:if>
79+
<f:section title="${%Console}">
80+
<form action="script" method="post">
81+
<textarea id="script" name="script" class="script">${request2.getParameter('script')}</textarea>
82+
<div align="right">
83+
<f:submit value="${%Run}"/>
84+
</div>
85+
</form>
86+
<st:adjunct includes="org.kohsuke.stapler.codemirror.mode.groovy.groovy"/>
87+
<st:adjunct includes="org.kohsuke.stapler.codemirror.theme.default"/>
88+
<j:if test="${output!=null}">
89+
<h2>
90+
${%Result}
91+
<l:copyButton text="${output}"/>
92+
</h2>
93+
<pre><st:out value="${output}"/></pre>
94+
</j:if>
95+
</f:section>
7496
</j:when>
7597
<j:otherwise>
7698
${%impossibleOffline}
7799
</j:otherwise>
78100
</j:choose>
79-
</l:main-panel>
80-
</l:layout>
101+
</d:tag>
102+
</d:taglib>
103+
104+
<j:choose>
105+
<j:when test="${attrs.layout == 'none'}">
106+
<local:contents>
107+
<d:invokeBody />
108+
</local:contents>
109+
</j:when>
110+
<j:otherwise>
111+
<j:set var="layout" value="${attrs.layout != null ? attrs.layout : 'two-column'}" />
112+
<l:layout permission="${app.ADMINISTER}" title="${%scriptConsole}" type="${layout}">
113+
<j:if test="${layout == 'two-column'}">
114+
<st:include page="sidepanel.jelly" />
115+
</j:if>
116+
117+
<l:breadcrumb title="${%scriptConsole}"/>
118+
<l:main-panel>
119+
<local:contents>
120+
<d:invokeBody />
121+
</local:contents>
122+
</l:main-panel>
123+
</l:layout>
124+
</j:otherwise>
125+
</j:choose>
81126
</j:jelly>

core/src/main/resources/lib/hudson/scriptConsole.properties

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,9 @@
2222

2323
description=\
2424
Type in an arbitrary <a href="https://www.groovy-lang.org">Groovy script</a> and \
25-
execute it on the server. Useful for trouble-shooting and diagnostics. \
26-
Use the ‘println’ command to see the output (if you use <code>System.out</code>, \
27-
it will go to the server’s stdout, which is harder to see.) Example:
25+
execute it on the server. Useful for trouble-shooting and diagnostics.
2826

29-
description2=\
30-
All the classes from all the plugins are visible. <code>jenkins.*</code>, <code>jenkins.model.*</code>, <code>hudson.*</code>, and <code>hudson.model.*</code> are pre-imported.
31-
clickToCopy=Click to copy
32-
successfullyCopied=Copied to clipboard
27+
instructions=\
28+
Use the ‘println’ command to see the output (if you use System.out, it will go to the server’s stdout, which is harder to see). All the classes from all the plugins are visible. <code>jenkins.*</code>, <code>jenkins.model.*</code>, <code>hudson.*</code>, and <code>hudson.model.*</code> are pre-imported.
3329
impossibleOffline=It is not possible to run scripts when agent is offline.
3430
scriptConsole=Script Console

src/main/scss/form/_layout.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
padding: 0 1rem;
9898
gap: 1.5rem;
9999

100-
.jenkins-copy-button {
100+
.jenkins-button {
101101
margin-top: 0.25rem;
102102
margin-bottom: 0.25rem;
103103
margin-right: -0.75rem;

0 commit comments

Comments
 (0)