From 89fa3a91a5e8450f3472ae0db5c24c4826bded37 Mon Sep 17 00:00:00 2001 From: Rodion Gushchin Date: Wed, 4 Dec 2019 10:18:39 +0100 Subject: [PATCH 01/10] Second stage fix of JENKINS-38669 --- pom.xml | 2 +- .../plugins/workflow/cps/CpsScmFlowDefinition.java | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 7f0ebda7a9..c8dac67bab 100644 --- a/pom.xml +++ b/pom.xml @@ -83,7 +83,7 @@ org.jenkins-ci.plugins.workflow workflow-api - 2.36 + 2.38-rc974.2eb15c40fbf9 org.jenkins-ci.plugins.workflow diff --git a/src/main/java/org/jenkinsci/plugins/workflow/cps/CpsScmFlowDefinition.java b/src/main/java/org/jenkinsci/plugins/workflow/cps/CpsScmFlowDefinition.java index 6e665a8bd8..6fcd7298df 100644 --- a/src/main/java/org/jenkinsci/plugins/workflow/cps/CpsScmFlowDefinition.java +++ b/src/main/java/org/jenkinsci/plugins/workflow/cps/CpsScmFlowDefinition.java @@ -46,6 +46,7 @@ import java.io.IOException; import java.io.InterruptedIOException; import java.util.Collection; +import java.util.Collections; import java.util.List; import jenkins.model.Jenkins; import jenkins.scm.api.SCMFileSystem; @@ -82,6 +83,11 @@ public SCM getScm() { return scm; } + @Override + public Collection getSCMs() { + return Collections.singletonList(scm); + } + public String getScriptPath() { return scriptPath; } From abd47336d746796ceccfd9f4692d0f5b2467f93d Mon Sep 17 00:00:00 2001 From: Liam Newman Date: Wed, 9 Jun 2021 15:25:25 -0700 Subject: [PATCH 02/10] Update pom.xml --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index c8dac67bab..09c239207d 100644 --- a/pom.xml +++ b/pom.xml @@ -83,7 +83,7 @@ org.jenkins-ci.plugins.workflow workflow-api - 2.38-rc974.2eb15c40fbf9 + 2.45-rc1080.0c008559cb45 org.jenkins-ci.plugins.workflow From 0b62ffeee546c7c144da7d2706b279227746f49c Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Fri, 3 Nov 2023 08:11:30 -0400 Subject: [PATCH 03/10] Test coverage for `evaluate`ing classes across restarts --- .../workflow/cps/CpsFlowExecutionTest.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/plugin/src/test/java/org/jenkinsci/plugins/workflow/cps/CpsFlowExecutionTest.java b/plugin/src/test/java/org/jenkinsci/plugins/workflow/cps/CpsFlowExecutionTest.java index 5ab076d9c9..d32acba684 100644 --- a/plugin/src/test/java/org/jenkinsci/plugins/workflow/cps/CpsFlowExecutionTest.java +++ b/plugin/src/test/java/org/jenkinsci/plugins/workflow/cps/CpsFlowExecutionTest.java @@ -692,6 +692,26 @@ public boolean isAllowed(String groovyResourceUrl) { } } + @Test public void evaluateAfterRestart() throws Throwable { + sessions.then(r -> { + WorkflowJob p = r.createProject(WorkflowJob.class, "p"); + p.setDefinition(new CpsFlowDefinition( + "def x = evaluate('class X {X() {}; def m1() {/OK/}}; new X()')\n" + + "def y = evaluate('class Y {X x; def m2() {/really ${x.m1()}/}}; new Y()')\n" + + "semaphore('wait')\n" + + "y.x = x\n" + + "echo(/received ${y.m2()}/)\n", true)); + WorkflowRun b = p.scheduleBuild2(0).waitForStart(); + SemaphoreStep.waitForStart("wait/1", b); + }); + sessions.then(r -> { + WorkflowJob p = r.jenkins.getItemByFullName("p", WorkflowJob.class); + WorkflowRun b = p.getLastBuild(); + SemaphoreStep.success("wait/1", null); + r.assertLogContains("received really OK", r.assertBuildStatus(Result.SUCCESS, r.waitForCompletion(b))); + }); + } + @Issue({ "JENKINS-45327", "JENKINS-68849" }) @Test public void envActionImplPickle() throws Throwable { sessions.then(r -> { From 1895fc16ebdf0e6e3464a0b687c4be7fb331f7ff Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 28 Nov 2023 12:21:11 -0500 Subject: [PATCH 04/10] Bump org.jenkins-ci.plugins:plugin from 4.74 to 4.75 (#811) Bumps [org.jenkins-ci.plugins:plugin](https://github.com/jenkinsci/plugin-pom) from 4.74 to 4.75. - [Release notes](https://github.com/jenkinsci/plugin-pom/releases) - [Changelog](https://github.com/jenkinsci/plugin-pom/blob/master/CHANGELOG.md) - [Commits](https://github.com/jenkinsci/plugin-pom/compare/plugin-4.74...plugin-4.75) --- updated-dependencies: - dependency-name: org.jenkins-ci.plugins:plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index a81243eaad..a071fbe647 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ org.jenkins-ci.plugins plugin - 4.74 + 4.75 org.jenkins-ci.plugins.workflow From d71a82f42f2f3b5585b6fd0ab9603e79bdfb6752 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 28 Nov 2023 12:21:22 -0500 Subject: [PATCH 05/10] Bump org.testcontainers:testcontainers from 1.19.0 to 1.19.3 (#818) Bumps [org.testcontainers:testcontainers](https://github.com/testcontainers/testcontainers-java) from 1.19.0 to 1.19.3. - [Release notes](https://github.com/testcontainers/testcontainers-java/releases) - [Changelog](https://github.com/testcontainers/testcontainers-java/blob/main/CHANGELOG.md) - [Commits](https://github.com/testcontainers/testcontainers-java/compare/1.19.0...1.19.3) --- updated-dependencies: - dependency-name: org.testcontainers:testcontainers dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- plugin/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/pom.xml b/plugin/pom.xml index ae5a4ebd78..10041e897c 100644 --- a/plugin/pom.xml +++ b/plugin/pom.xml @@ -253,7 +253,7 @@ org.testcontainers testcontainers - 1.19.0 + 1.19.3 test From e64a8c656acbad4f50d05389f6adb147dcddafea Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 28 Nov 2023 12:21:32 -0500 Subject: [PATCH 06/10] Bump org.codehaus.mojo:exec-maven-plugin from 3.1.0 to 3.1.1 (#816) Bumps [org.codehaus.mojo:exec-maven-plugin](https://github.com/mojohaus/exec-maven-plugin) from 3.1.0 to 3.1.1. - [Release notes](https://github.com/mojohaus/exec-maven-plugin/releases) - [Commits](https://github.com/mojohaus/exec-maven-plugin/compare/exec-maven-plugin-3.1.0...3.1.1) --- updated-dependencies: - dependency-name: org.codehaus.mojo:exec-maven-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- lib/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pom.xml b/lib/pom.xml index 246abc5577..02373e4385 100644 --- a/lib/pom.xml +++ b/lib/pom.xml @@ -50,7 +50,7 @@ org.codehaus.mojo exec-maven-plugin - 3.1.0 + 3.1.1 generate-sources From c3031abac9558e64029772be9dc529f59c190a6e Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Tue, 28 Nov 2023 12:21:43 -0500 Subject: [PATCH 07/10] Use `ComponentCategory.BUILDS` (#814) * Use `ComponentCategory.BUILDS` * Incremental build * https://github.com/jenkinsci/workflow-cps-plugin/pull/814#issuecomment-1820070453 --- plugin/pom.xml | 6 ++++++ .../jenkinsci/plugins/workflow/cps/CpsFlowExecution.java | 8 ++++++++ .../plugins/workflow/cps/CpsThreadDumpAction.java | 4 ++++ 3 files changed, 18 insertions(+) diff --git a/plugin/pom.xml b/plugin/pom.xml index 10041e897c..54d8890b1e 100644 --- a/plugin/pom.xml +++ b/plugin/pom.xml @@ -54,6 +54,12 @@ import pom + + + org.jenkins-ci.plugins + support-core + 1366.v9d076592655d + diff --git a/plugin/src/main/java/org/jenkinsci/plugins/workflow/cps/CpsFlowExecution.java b/plugin/src/main/java/org/jenkinsci/plugins/workflow/cps/CpsFlowExecution.java index ded38b7b0f..683eecdf97 100644 --- a/plugin/src/main/java/org/jenkinsci/plugins/workflow/cps/CpsFlowExecution.java +++ b/plugin/src/main/java/org/jenkinsci/plugins/workflow/cps/CpsFlowExecution.java @@ -2020,6 +2020,10 @@ public void autopersist(@NonNull FlowNode n) throws IOException { return "Timing data about recently completed Pipeline builds"; } + @Override public ComponentCategory getCategory() { + return ComponentCategory.BUILDS; + } + @Override public void addContents(Container container) { container.add(new Content("nodes/master/pipeline-timings.txt") { @Override public void writeTo(OutputStream outputStream) throws IOException { @@ -2067,6 +2071,10 @@ public void autopersist(@NonNull FlowNode n) throws IOException { return "List of internal API calls made by Pipeline builds (typically from trusted libraries)"; } + @Override public ComponentCategory getCategory() { + return ComponentCategory.BUILDS; + } + @Override public void addContents(Container container) { container.add(new Content("nodes/master/pipeline-internal-calls.txt") { @Override public void writeTo(OutputStream outputStream) throws IOException { diff --git a/plugin/src/main/java/org/jenkinsci/plugins/workflow/cps/CpsThreadDumpAction.java b/plugin/src/main/java/org/jenkinsci/plugins/workflow/cps/CpsThreadDumpAction.java index 8fdf86ad32..835f271de1 100644 --- a/plugin/src/main/java/org/jenkinsci/plugins/workflow/cps/CpsThreadDumpAction.java +++ b/plugin/src/main/java/org/jenkinsci/plugins/workflow/cps/CpsThreadDumpAction.java @@ -102,6 +102,10 @@ public CpsThreadDump getThreadDump() { return "Thread dumps of running Pipeline builds"; } + @Override public ComponentCategory getCategory() { + return ComponentCategory.BUILDS; + } + @Override public void addContents(Container container) { container.add(new Content("nodes/master/pipeline-thread-dump.txt") { @Override public void writeTo(OutputStream outputStream) throws IOException { From 28eded5d3408ea41efd9b8e7232f9a8f64a624fd Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Mon, 4 Dec 2023 13:06:47 -0500 Subject: [PATCH 08/10] Suppress ESLint warning `no-unused-vars` --- plugin/src/main/js/workflow-editor.js | 1 + 1 file changed, 1 insertion(+) diff --git a/plugin/src/main/js/workflow-editor.js b/plugin/src/main/js/workflow-editor.js index 81da7098cf..faf344ef1f 100644 --- a/plugin/src/main/js/workflow-editor.js +++ b/plugin/src/main/js/workflow-editor.js @@ -54,6 +54,7 @@ $(function() { setTheme(editor); if (window.isSystemRespectingTheme) { + // eslint-disable-next-line no-unused-vars window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', event => { setTheme(editor) }); From dee5500af30b068621abf27f2c8a5846b764a934 Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Mon, 4 Dec 2023 15:36:44 -0500 Subject: [PATCH 09/10] Do not request unused `event` parameter Co-authored-by: Basil Crow --- plugin/src/main/js/workflow-editor.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugin/src/main/js/workflow-editor.js b/plugin/src/main/js/workflow-editor.js index faf344ef1f..486d6b0d3a 100644 --- a/plugin/src/main/js/workflow-editor.js +++ b/plugin/src/main/js/workflow-editor.js @@ -54,8 +54,7 @@ $(function() { setTheme(editor); if (window.isSystemRespectingTheme) { - // eslint-disable-next-line no-unused-vars - window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', event => { + window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', () => { setTheme(editor) }); } From 9d3888c583b10fcbad8b006d4697be25af45ddd8 Mon Sep 17 00:00:00 2001 From: Arthur Caron Date: Thu, 7 Dec 2023 14:35:41 +0100 Subject: [PATCH 10/10] [JENKINS-69917] - Snippetizer/index.jelly javascript un-inlined. (#599) * [JENKINS-69917] - Snippetizer/index.jelly javascript un-inlined. * [JENKINS-69917] - Attribute used to pass url from jelly to JS. * [JENKINS-69917] - Apply suggestions from code review Co-authored-by: Jesse Glick * [JENKINS-69917] - handle-prototype fixed. * [JENKINS-69917] - handle-prototype use fetch. --------- Co-authored-by: Jesse Glick --- .../cps/Snippetizer/handle-prototype.js | 43 +++++++++++++++++++ .../workflow/cps/Snippetizer/index.jelly | 35 +++------------ 2 files changed, 49 insertions(+), 29 deletions(-) create mode 100644 plugin/src/main/resources/org/jenkinsci/plugins/workflow/cps/Snippetizer/handle-prototype.js diff --git a/plugin/src/main/resources/org/jenkinsci/plugins/workflow/cps/Snippetizer/handle-prototype.js b/plugin/src/main/resources/org/jenkinsci/plugins/workflow/cps/Snippetizer/handle-prototype.js new file mode 100644 index 0000000000..79e7d5569c --- /dev/null +++ b/plugin/src/main/resources/org/jenkinsci/plugins/workflow/cps/Snippetizer/handle-prototype.js @@ -0,0 +1,43 @@ +function handlePrototype(url, crumb) { + buildFormTree(document.forms.config); + // TODO JSON.stringify fails in some circumstances: https://gist.github.com/jglick/70ec4b15c1f628fdf2e9 due to Array.prototype.toJSON + // TODO simplify when Prototype.js is removed + 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); + if (!json) { + return; // just a separator + } + + const headers = new Headers(); + headers.append("Content-Type", "application/x-www-form-urlencoded"); + headers.append("Jenkins-Crumb", crumb); + + fetch(url, { + method: "POST", + headers: headers, + body: "json=" + encodeURIComponent(json), + + }) + .then(response => { + if (response.ok) { + response.text().then((responseText) => { + document.getElementById('prototypeText').value = responseText; + }); + } + }) + .catch(error => { + console.error('Fetch error:', error); + }); +} + + +document.addEventListener('DOMContentLoaded', () => { + + const generatePipelineScript = document.getElementById("generatePipelineScript"); + const url = generatePipelineScript.getAttribute("data-url"); + const crumb = generatePipelineScript.getAttribute("data-crumb"); + generatePipelineScript.onclick = (_) => { + handlePrototype(url, crumb); + return false; + }; + +}); \ No newline at end of file diff --git a/plugin/src/main/resources/org/jenkinsci/plugins/workflow/cps/Snippetizer/index.jelly b/plugin/src/main/resources/org/jenkinsci/plugins/workflow/cps/Snippetizer/index.jelly index 262dd07472..1394a54584 100644 --- a/plugin/src/main/resources/org/jenkinsci/plugins/workflow/cps/Snippetizer/index.jelly +++ b/plugin/src/main/resources/org/jenkinsci/plugins/workflow/cps/Snippetizer/index.jelly @@ -67,36 +67,13 @@ THE SOFTWARE. - - - - + + +