Skip to content

Commit e47101f

Browse files
committed
Merge branch 'master' into JENKINS-70695
2 parents 4a01731 + 9d3888c commit e47101f

File tree

10 files changed

+101
-37
lines changed

10 files changed

+101
-37
lines changed

lib/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
<plugin>
5151
<groupId>org.codehaus.mojo</groupId>
5252
<artifactId>exec-maven-plugin</artifactId>
53-
<version>3.1.0</version>
53+
<version>3.1.1</version>
5454
<executions>
5555
<execution>
5656
<phase>generate-sources</phase>

plugin/pom.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@
5454
<scope>import</scope>
5555
<type>pom</type>
5656
</dependency>
57+
<!-- TODO until in BOM: -->
58+
<dependency>
59+
<groupId>org.jenkins-ci.plugins</groupId>
60+
<artifactId>support-core</artifactId>
61+
<version>1366.v9d076592655d</version>
62+
</dependency>
5763
</dependencies>
5864
</dependencyManagement>
5965
<dependencies>
@@ -253,7 +259,7 @@
253259
<dependency>
254260
<groupId>org.testcontainers</groupId>
255261
<artifactId>testcontainers</artifactId>
256-
<version>1.19.0</version>
262+
<version>1.19.3</version>
257263
<scope>test</scope>
258264
<exclusions>
259265
<!-- Provided by Jenkins core -->

plugin/src/main/java/org/jenkinsci/plugins/workflow/cps/CpsFlowExecution.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2020,6 +2020,10 @@ public void autopersist(@NonNull FlowNode n) throws IOException {
20202020
return "Timing data about recently completed Pipeline builds";
20212021
}
20222022

2023+
@Override public ComponentCategory getCategory() {
2024+
return ComponentCategory.BUILDS;
2025+
}
2026+
20232027
@Override public void addContents(Container container) {
20242028
container.add(new Content("nodes/master/pipeline-timings.txt") {
20252029
@Override public void writeTo(OutputStream outputStream) throws IOException {
@@ -2067,6 +2071,10 @@ public void autopersist(@NonNull FlowNode n) throws IOException {
20672071
return "List of internal API calls made by Pipeline builds (typically from trusted libraries)";
20682072
}
20692073

2074+
@Override public ComponentCategory getCategory() {
2075+
return ComponentCategory.BUILDS;
2076+
}
2077+
20702078
@Override public void addContents(Container container) {
20712079
container.add(new Content("nodes/master/pipeline-internal-calls.txt") {
20722080
@Override public void writeTo(OutputStream outputStream) throws IOException {

plugin/src/main/java/org/jenkinsci/plugins/workflow/cps/CpsScmFlowDefinition.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import java.io.IOException;
4747
import java.io.InterruptedIOException;
4848
import java.util.Collection;
49+
import java.util.Collections;
4950
import java.util.List;
5051
import jenkins.model.Jenkins;
5152
import jenkins.scm.api.SCMFileSystem;
@@ -85,6 +86,11 @@ public SCM getScm() {
8586
return scm;
8687
}
8788

89+
@Override
90+
public Collection<? extends SCM> getSCMs() {
91+
return Collections.singletonList(scm);
92+
}
93+
8894
public String getScriptPath() {
8995
return scriptPath;
9096
}

plugin/src/main/java/org/jenkinsci/plugins/workflow/cps/CpsThreadDumpAction.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ public CpsThreadDump getThreadDump() {
102102
return "Thread dumps of running Pipeline builds";
103103
}
104104

105+
@Override public ComponentCategory getCategory() {
106+
return ComponentCategory.BUILDS;
107+
}
108+
105109
@Override public void addContents(Container container) {
106110
container.add(new Content("nodes/master/pipeline-thread-dump.txt") {
107111
@Override public void writeTo(OutputStream outputStream) throws IOException {

plugin/src/main/js/workflow-editor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ $(function() {
5454
setTheme(editor);
5555

5656
if (window.isSystemRespectingTheme) {
57-
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', event => {
57+
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', () => {
5858
setTheme(editor)
5959
});
6060
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
function handlePrototype(url, crumb) {
2+
buildFormTree(document.forms.config);
3+
// TODO JSON.stringify fails in some circumstances: https://gist.github.com/jglick/70ec4b15c1f628fdf2e9 due to Array.prototype.toJSON
4+
// TODO simplify when Prototype.js is removed
5+
const json = Object.toJSON ? Object.toJSON(JSON.parse(document.forms.config.elements.json.value).prototype) : JSON.stringify(JSON.parse(document.forms.config.elements.json.value).prototype);
6+
if (!json) {
7+
return; // just a separator
8+
}
9+
10+
const headers = new Headers();
11+
headers.append("Content-Type", "application/x-www-form-urlencoded");
12+
headers.append("Jenkins-Crumb", crumb);
13+
14+
fetch(url, {
15+
method: "POST",
16+
headers: headers,
17+
body: "json=" + encodeURIComponent(json),
18+
19+
})
20+
.then(response => {
21+
if (response.ok) {
22+
response.text().then((responseText) => {
23+
document.getElementById('prototypeText').value = responseText;
24+
copybutton = document.querySelector('.jenkins-copy-button');
25+
copybutton.setAttribute("text", responseText);
26+
copybutton.classList.remove('jenkins-hidden');
27+
});
28+
}
29+
})
30+
.catch(error => {
31+
console.error('Fetch error:', error);
32+
});
33+
}
34+
35+
36+
document.addEventListener('DOMContentLoaded', () => {
37+
38+
const generatePipelineScript = document.getElementById("generatePipelineScript");
39+
const url = generatePipelineScript.getAttribute("data-url");
40+
const crumb = generatePipelineScript.getAttribute("data-crumb");
41+
generatePipelineScript.onclick = (_) => {
42+
handlePrototype(url, crumb);
43+
return false;
44+
};
45+
46+
});

plugin/src/main/resources/org/jenkinsci/plugins/workflow/cps/Snippetizer/index.jelly

Lines changed: 7 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -67,40 +67,14 @@ THE SOFTWARE.
6767
<f:dropdownListBlock title="${%— Advanced/Deprecated —}"/>
6868
<local:listSteps quasiDescriptors="${it.getQuasiDescriptors(true)}"/>
6969
</f:dropdownList>
70-
<j:set var="id" value="${h.generateId()}"/>
7170
<f:block>
72-
<input type="button" value="${%Generate Pipeline Script}" onclick="handlePrototype_${id}(); return false" class="submit-button primary"/>
73-
<f:textarea id="prototypeText_${id}" readonly="true" style="margin-top: 10px; margin-bottom: 5px" />
74-
<l:copyButton text="" clazz="jenkins-hidden"/>
75-
<script>
76-
function handlePrototype_${id}() {
77-
buildFormTree(document.forms.config);
78-
// TODO JSON.stringify fails in some circumstances: https://gist.github.com/jglick/70ec4b15c1f628fdf2e9 due to Array.prototype.toJSON
79-
// TODO simplify when Prototype.js is removed
80-
var json = Object.toJSON ? Object.toJSON(JSON.parse(document.forms.config.elements.json.value).prototype) : JSON.stringify(JSON.parse(document.forms.config.elements.json.value).prototype);
81-
if (!json) {
82-
return; // just a separator
83-
}
84-
fetch('${rootURL}/${it.GENERATE_URL}', {
85-
method: 'post',
86-
headers: crumb.wrap({
87-
"Content-Type": "application/x-www-form-urlencoded",
88-
}),
89-
body: new URLSearchParams({
90-
json: json,
91-
}),
92-
}).then((rsp) => {
93-
if (rsp.ok) {
94-
rsp.text().then((responseText) => {
95-
document.getElementById('prototypeText_${id}').value = responseText;
96-
copybutton = document.querySelector('.jenkins-copy-button');
97-
copybutton.setAttribute("text", r.responseText);
98-
copybutton.classList.remove('jenkins-hidden');
99-
});
100-
}
101-
});
102-
}
103-
</script>
71+
<input type="button" id="generatePipelineScript" value="${%Generate Pipeline Script}"
72+
class="submit-button primary"
73+
data-url="${rootURL}/${it.GENERATE_URL}"
74+
data-crumb="${h.getCrumb(request)}"/>
75+
<f:textarea id="prototypeText" readonly="true" style="margin-top: 10px"/>
76+
<l:copyButton text="" clazz="jenkins-hidden jenkins-!-margin-top-1"/>
77+
<st:adjunct includes="org.jenkinsci.plugins.workflow.cps.Snippetizer.handle-prototype"/>
10478
</f:block>
10579
<f:section title="${%Global Variables}"/>
10680
<f:block>

plugin/src/test/java/org/jenkinsci/plugins/workflow/cps/CpsFlowExecutionTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,26 @@ public boolean isAllowed(String groovyResourceUrl) {
703703
}
704704
}
705705

706+
@Test public void evaluateAfterRestart() throws Throwable {
707+
sessions.then(r -> {
708+
WorkflowJob p = r.createProject(WorkflowJob.class, "p");
709+
p.setDefinition(new CpsFlowDefinition(
710+
"def x = evaluate('class X {X() {}; def m1() {/OK/}}; new X()')\n" +
711+
"def y = evaluate('class Y {X x; def m2() {/really ${x.m1()}/}}; new Y()')\n" +
712+
"semaphore('wait')\n" +
713+
"y.x = x\n" +
714+
"echo(/received ${y.m2()}/)\n", true));
715+
WorkflowRun b = p.scheduleBuild2(0).waitForStart();
716+
SemaphoreStep.waitForStart("wait/1", b);
717+
});
718+
sessions.then(r -> {
719+
WorkflowJob p = r.jenkins.getItemByFullName("p", WorkflowJob.class);
720+
WorkflowRun b = p.getLastBuild();
721+
SemaphoreStep.success("wait/1", null);
722+
r.assertLogContains("received really OK", r.assertBuildStatus(Result.SUCCESS, r.waitForCompletion(b)));
723+
});
724+
}
725+
706726
@Issue({ "JENKINS-45327", "JENKINS-68849" })
707727
@Test public void envActionImplPickle() throws Throwable {
708728
sessions.then(r -> {

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>org.jenkins-ci.plugins</groupId>
66
<artifactId>plugin</artifactId>
7-
<version>4.74</version>
7+
<version>4.75</version>
88
<relativePath/>
99
</parent>
1010
<groupId>org.jenkins-ci.plugins.workflow</groupId>

0 commit comments

Comments
 (0)