From 9476558d65d726be50719e6e6ee66ea8fdf23c03 Mon Sep 17 00:00:00 2001 From: olivier lamy Date: Wed, 20 Jan 2021 12:26:31 +1000 Subject: [PATCH 01/34] upgrade release drafter and add dependabot for ghactions Signed-off-by: olivier lamy --- .github/dependabot.yml | 4 ++++ .github/workflows/release-drafter.yml | 5 ++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 563d580..fdc58d1 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -6,3 +6,7 @@ updates: directory: "/" schedule: interval: "weekly" + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml index 832442d..b7bb83b 100644 --- a/.github/workflows/release-drafter.yml +++ b/.github/workflows/release-drafter.yml @@ -1,16 +1,15 @@ # Automates creation of Release Drafts using Release Drafter # More Info: https://github.com/jenkinsci/.github/blob/master/.github/release-drafter.adoc +name: Release Drafter on: push: branches: - master - jobs: update_release_draft: runs-on: ubuntu-latest steps: - # Drafts your next Release notes as Pull Requests are merged into "master" - - uses: release-drafter/release-drafter@v5 + - uses: release-drafter/release-drafter@v5.13.0 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 9bda7b99eda027ec3e0eb6e23a740984faeffce9 Mon Sep 17 00:00:00 2001 From: olivier lamy Date: Thu, 21 Jan 2021 15:59:32 +1000 Subject: [PATCH 02/34] add junit for stash file parameter Signed-off-by: olivier lamy --- README.md | 2 +- .../FileParameterWrapperTest.java | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 613526c..bd79072 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ See [JENKINS-27413](https://issues.jenkins-ci.org/browse/JENKINS-27413) and [JEN - [ ] inline help text - [ ] `withFileParameter` compatibility - [X] manual test - - [ ] automated test + - [X] automated test - [ ] sanity check against `artifact-manager-s3` - [ ] archived file parameter (compatible with freestyle, and suitable if you want to ensure parameters are kept after the build ends) - [ ] implementation diff --git a/src/test/java/io/jenkins/plugins/file_parameters/FileParameterWrapperTest.java b/src/test/java/io/jenkins/plugins/file_parameters/FileParameterWrapperTest.java index 51ecb1b..a44c58d 100644 --- a/src/test/java/io/jenkins/plugins/file_parameters/FileParameterWrapperTest.java +++ b/src/test/java/io/jenkins/plugins/file_parameters/FileParameterWrapperTest.java @@ -58,4 +58,20 @@ public class FileParameterWrapperTest { r.assertLogContains("loaded 'UPLOADED CONTENT HERE' from ", b); } + @Test public void stashed() throws Exception { + r.createSlave("remote", null, null); + WorkflowJob p = r.createProject(WorkflowJob.class, "myjob"); + p.addProperty(new ParametersDefinitionProperty(new StashedFileParameterDefinition("FILE-STASH", null))); + p.setDefinition(new CpsFlowDefinition("node('remote') {" + + " unstash \"FILE-STASH\"\n" + + " echo(/loaded '${readFile(\"FILE-STASH\").toUpperCase(Locale.ROOT)}'/)}", true)); + assertThat(new CLICommandInvoker(r, "build"). + withStdin(new ByteArrayInputStream("uploaded content here".getBytes())). + invokeWithArgs("-f", "-p", "FILE-STASH=", "myjob"), + CLICommandInvoker.Matcher.succeeded()); + WorkflowRun b = p.getBuildByNumber(1); + assertNotNull(b); + r.assertLogContains("loaded 'UPLOADED CONTENT HERE'", b); + } + } From 9dc68fa0088f5876a86c6df6b5a6c50a42247229 Mon Sep 17 00:00:00 2001 From: olivier lamy Date: Fri, 22 Jan 2021 08:12:59 +1000 Subject: [PATCH 03/34] add more details on manual tests done Signed-off-by: olivier lamy --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index bd79072..d00cef6 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ See [JENKINS-27413](https://issues.jenkins-ci.org/browse/JENKINS-27413) and [JEN - [ ] stashed file parameter (suitable for larger files used in Pipeline) - [X] implementation - [ ] inline help text - - [ ] `withFileParameter` compatibility + - [X] `withFileParameter` compatibility (manual test) - [X] manual test - [X] automated test - [ ] sanity check against `artifact-manager-s3` @@ -48,7 +48,7 @@ See [JENKINS-27413](https://issues.jenkins-ci.org/browse/JENKINS-27413) and [JEN - [ ] `withFileParameter` wrapper step - [X] implementation - [X] inline help text - - [ ] manual test + - [X] manual test - [X] automated test - [ ] option to tolerate undefined parameter - [ ] `input` step submission From 542a861f73e36cf6b5b352120d4fff518fc98f88 Mon Sep 17 00:00:00 2001 From: olivier lamy Date: Fri, 22 Jan 2021 15:36:15 +1000 Subject: [PATCH 04/34] add more docs and inline help Signed-off-by: olivier lamy --- README.md | 25 +++++++++++++++++++ .../Base64FileParameterDefinition.java | 6 +++++ .../StashedFileParameterDefinition.java | 5 ++++ src/main/webapp/help-base64File.html | 20 +++++++++++++++ src/main/webapp/help-stashedFile.html | 19 ++++++++++++++ .../FileParameterWrapperTest.java | 1 + 6 files changed, 76 insertions(+) create mode 100644 src/main/webapp/help-base64File.html create mode 100644 src/main/webapp/help-stashedFile.html diff --git a/README.md b/README.md index d00cef6..5eb1008 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,31 @@ Offers alternative types of file parameter that are compatible with Pipeline and See [JENKINS-27413](https://issues.jenkins-ci.org/browse/JENKINS-27413) and [JENKINS-29289](https://issues.jenkins-ci.org/browse/JENKINS-29289) for background. +## Usage in declarative pipeline + +You can now declare file parameters as is in declarative pipeline: + +``` +pipeline { + agent any + parameters { + base64File(name: 'FILE') + stashed64File(name: 'FILE-STASH') + } + stages { + stage('Example') { + steps { + withFileParameter('FILE') { + echo(/loaded '${readFile(FILE)}' from $FILE/) + } + unstash "FILE-STASH" + echo(/loaded '${readFile("./FILE-STASH")}'/) + } + } + } +} +``` + ## Implementation status - [X] Base64 file parameter (simple and suitable for small files) diff --git a/src/main/java/io/jenkins/plugins/file_parameters/Base64FileParameterDefinition.java b/src/main/java/io/jenkins/plugins/file_parameters/Base64FileParameterDefinition.java index 532a2cb..c5dde18 100644 --- a/src/main/java/io/jenkins/plugins/file_parameters/Base64FileParameterDefinition.java +++ b/src/main/java/io/jenkins/plugins/file_parameters/Base64FileParameterDefinition.java @@ -54,6 +54,12 @@ public final class Base64FileParameterDefinition extends AbstractFileParameterDe return "Base64 File Parameter"; } + @Override public String getHelpFile() + { + return "/plugin/file-parameters/help-base64File.html"; + } } + + } diff --git a/src/main/java/io/jenkins/plugins/file_parameters/StashedFileParameterDefinition.java b/src/main/java/io/jenkins/plugins/file_parameters/StashedFileParameterDefinition.java index 46d4ca1..c1b4d9c 100644 --- a/src/main/java/io/jenkins/plugins/file_parameters/StashedFileParameterDefinition.java +++ b/src/main/java/io/jenkins/plugins/file_parameters/StashedFileParameterDefinition.java @@ -54,6 +54,11 @@ public final class StashedFileParameterDefinition extends AbstractFileParameterD return "Stashed File Parameter"; } + @Override public String getHelpFile() + { + return "/plugin/file-parameters/help-stashedFile.html"; + } + } } diff --git a/src/main/webapp/help-base64File.html b/src/main/webapp/help-base64File.html new file mode 100644 index 0000000..c12551e --- /dev/null +++ b/src/main/webapp/help-base64File.html @@ -0,0 +1,20 @@ +
+

File parameter compatible with Pipeline, how to use it in a declarative pipeline:

+
+pipeline {
+  agent any
+  parameters {
+    base64File(name: 'THEFILE')
+  }
+  stages {
+    stage('Example') {
+      steps {
+        withFileParameter('THEFILE') {
+        echo(/loaded '${readFile(FILE)}' from $FILE/)
+        }
+      }
+    }
+  }
+}
+  
+
diff --git a/src/main/webapp/help-stashedFile.html b/src/main/webapp/help-stashedFile.html new file mode 100644 index 0000000..b57a72d --- /dev/null +++ b/src/main/webapp/help-stashedFile.html @@ -0,0 +1,19 @@ +
+

File parameter compatible with Pipeline but this one stash the file, how to use it in a declarative pipeline:

+
+pipeline {
+  agent any
+  parameters {
+    stashed64File(name: 'FILE-STASH')
+  }
+  stages {
+    stage('Example') {
+      steps {
+        unstash "FILE-STASH"
+        echo(/loaded '${readFile("./FILE-STASH")}'/)
+      }
+    }
+  }
+}
+ 
+
diff --git a/src/test/java/io/jenkins/plugins/file_parameters/FileParameterWrapperTest.java b/src/test/java/io/jenkins/plugins/file_parameters/FileParameterWrapperTest.java index a44c58d..9800ddf 100644 --- a/src/test/java/io/jenkins/plugins/file_parameters/FileParameterWrapperTest.java +++ b/src/test/java/io/jenkins/plugins/file_parameters/FileParameterWrapperTest.java @@ -65,6 +65,7 @@ public class FileParameterWrapperTest { p.setDefinition(new CpsFlowDefinition("node('remote') {" + " unstash \"FILE-STASH\"\n" + " echo(/loaded '${readFile(\"FILE-STASH\").toUpperCase(Locale.ROOT)}'/)}", true)); + assertThat(new CLICommandInvoker(r, "build"). withStdin(new ByteArrayInputStream("uploaded content here".getBytes())). invokeWithArgs("-f", "-p", "FILE-STASH=", "myjob"), From 83d4e02bf74aa9ce9cb32efa2b595b14d336a242 Mon Sep 17 00:00:00 2001 From: olivier lamy Date: Fri, 22 Jan 2021 15:36:49 +1000 Subject: [PATCH 05/34] mar inline help as done Signed-off-by: olivier lamy --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5eb1008..6a53ae9 100644 --- a/README.md +++ b/README.md @@ -41,13 +41,13 @@ pipeline { - [X] Base64 file parameter (simple and suitable for small files) - [X] implementation - - [ ] inline help text + - [X] inline help text - [X] `withFileParameter` compatibility - [X] manual test - [X] automated test - [ ] stashed file parameter (suitable for larger files used in Pipeline) - [X] implementation - - [ ] inline help text + - [X] inline help text - [X] `withFileParameter` compatibility (manual test) - [X] manual test - [X] automated test From a3e2f5697996ba3c06f63b3f9a2b3a6956c8d67f Mon Sep 17 00:00:00 2001 From: olivier lamy Date: Fri, 22 Jan 2021 16:22:37 +1000 Subject: [PATCH 06/34] add more tests including auto creation of build parameters with pipeline Signed-off-by: olivier lamy --- pom.xml | 10 +++ .../FileParameterWrapperTest.java | 82 +++++++++++++++++++ 2 files changed, 92 insertions(+) diff --git a/pom.xml b/pom.xml index 5ecc5c7..2ee1026 100644 --- a/pom.xml +++ b/pom.xml @@ -30,6 +30,11 @@ import pom + + com.fasterxml.jackson.datatype + jackson-datatype-json-org + 2.12.1 + @@ -62,6 +67,11 @@ workflow-basic-steps test + + org.jenkinsci.plugins + pipeline-model-definition + test + diff --git a/src/test/java/io/jenkins/plugins/file_parameters/FileParameterWrapperTest.java b/src/test/java/io/jenkins/plugins/file_parameters/FileParameterWrapperTest.java index 9800ddf..183072e 100644 --- a/src/test/java/io/jenkins/plugins/file_parameters/FileParameterWrapperTest.java +++ b/src/test/java/io/jenkins/plugins/file_parameters/FileParameterWrapperTest.java @@ -25,9 +25,12 @@ package io.jenkins.plugins.file_parameters; import hudson.cli.CLICommandInvoker; +import hudson.model.ParameterDefinition; import hudson.model.ParametersDefinitionProperty; import java.io.ByteArrayInputStream; import static org.hamcrest.MatcherAssert.assertThat; + +import hudson.model.Result; import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition; import org.jenkinsci.plugins.workflow.job.WorkflowJob; import org.jenkinsci.plugins.workflow.job.WorkflowRun; @@ -58,6 +61,46 @@ public class FileParameterWrapperTest { r.assertLogContains("loaded 'UPLOADED CONTENT HERE' from ", b); } + @Test public void base64DeclarativeParameterCreated() throws Exception { + r.createSlave("remote", null, null); + WorkflowJob p = r.createProject(WorkflowJob.class, "myjob"); + + String pipeline = "pipeline {\n" + + " agent any\n" + + " parameters {\n" + + " base64File(name: 'FILE')\n" + + " }\n" + + " stages {\n" + + " stage('Example') {\n" + + " steps {\n" + + " withFileParameter('FILE') {\n" + + " echo(/loaded '${readFile(FILE).toUpperCase(Locale.ROOT)}' from $FILE/) \n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "}"; + + p.setDefinition(new CpsFlowDefinition(pipeline, true)); + WorkflowRun run = p.scheduleBuild2(0).get(); + r.waitForCompletion(run); + // definitely will fail but we just ensure parameter has been created + r.assertBuildStatus(Result.FAILURE, run); + ParametersDefinitionProperty pdp = p.getProperty(ParametersDefinitionProperty.class); + assertNotNull("parameters definition property is null", pdp); + ParameterDefinition pd = pdp.getParameterDefinition( "FILE"); + assertNotNull("parameters definition is null", pd); + assertEquals("parameter not type Base64FileParameterDefinition", Base64FileParameterDefinition.class, pd.getClass()); + + assertThat(new CLICommandInvoker(r, "build"). + withStdin(new ByteArrayInputStream("uploaded content here".getBytes())). + invokeWithArgs("-f", "-p", "FILE=", "myjob"), + CLICommandInvoker.Matcher.succeeded()); + WorkflowRun b = p.getBuildByNumber(2); + assertNotNull(b); + r.assertLogContains("loaded 'UPLOADED CONTENT HERE'", b); + } + @Test public void stashed() throws Exception { r.createSlave("remote", null, null); WorkflowJob p = r.createProject(WorkflowJob.class, "myjob"); @@ -75,4 +118,43 @@ public class FileParameterWrapperTest { r.assertLogContains("loaded 'UPLOADED CONTENT HERE'", b); } + @Test public void stashedDeclarativeParameterCreated() throws Exception { + r.createSlave("remote", null, null); + WorkflowJob p = r.createProject(WorkflowJob.class, "myjob"); + + String pipeline = "pipeline {\n" + + " agent any\n" + + " parameters {\n" + + " stashed64File(name: 'FILE-STASH')\n" + + " }\n" + + " stages {\n" + + " stage('Example') {\n" + + " steps {\n" + + " unstash \"FILE-STASH\"\n" + + " echo(/loaded '${readFile(\"./FILE-STASH\").toUpperCase(Locale.ROOT)}'/) \n" + + " }\n" + + " }\n" + + " }\n" + + "}"; + + p.setDefinition(new CpsFlowDefinition(pipeline, true)); + WorkflowRun run = p.scheduleBuild2(0).get(); + r.waitForCompletion(run); + // definitely will fail but we just ensure parameter has been created + r.assertBuildStatus(Result.FAILURE, run); + ParametersDefinitionProperty pdp = p.getProperty(ParametersDefinitionProperty.class); + assertNotNull("parameters definition property is null", pdp); + ParameterDefinition pd = pdp.getParameterDefinition( "FILE-STASH"); + assertNotNull("parameters definition is null", pd); + assertEquals("parameter not type Base64FileParameterDefinition", StashedFileParameterDefinition.class, pd.getClass()); + + assertThat(new CLICommandInvoker(r, "build"). + withStdin(new ByteArrayInputStream("uploaded content here".getBytes())). + invokeWithArgs("-f", "-p", "FILE-STASH=", "myjob"), + CLICommandInvoker.Matcher.succeeded()); + WorkflowRun b = p.getBuildByNumber(2); + assertNotNull(b); + r.assertLogContains("loaded 'UPLOADED CONTENT HERE'", b); + } + } From 779d206d2f1a250f3bf24f813b6359eaf1eacbaf Mon Sep 17 00:00:00 2001 From: olivier lamy Date: Fri, 22 Jan 2021 21:11:18 +1000 Subject: [PATCH 07/34] add ignored test for a coming feature Signed-off-by: olivier lamy --- .../FileParameterWrapperTest.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/test/java/io/jenkins/plugins/file_parameters/FileParameterWrapperTest.java b/src/test/java/io/jenkins/plugins/file_parameters/FileParameterWrapperTest.java index 183072e..f0a2fa3 100644 --- a/src/test/java/io/jenkins/plugins/file_parameters/FileParameterWrapperTest.java +++ b/src/test/java/io/jenkins/plugins/file_parameters/FileParameterWrapperTest.java @@ -35,6 +35,7 @@ import org.jenkinsci.plugins.workflow.job.WorkflowJob; import org.jenkinsci.plugins.workflow.job.WorkflowRun; import org.junit.ClassRule; +import org.junit.Ignore; import org.junit.Test; import static org.junit.Assert.*; import org.junit.Rule; @@ -61,6 +62,35 @@ public class FileParameterWrapperTest { r.assertLogContains("loaded 'UPLOADED CONTENT HERE' from ", b); } + @Ignore("need to implement option to tolerate undefined parameter") + @Test public void base64Undefined() throws Exception { + r.createSlave("remote", null, null); + WorkflowJob p = r.createProject(WorkflowJob.class, "myjob"); + p.addProperty(new ParametersDefinitionProperty(new Base64FileParameterDefinition("FILE", null))); + String pipeline = "pipeline {\n" + + " agent any\n" + + " parameters {\n" + + " base64File(name: 'FILE')\n" + + " }\n" + + " stages {\n" + + " stage('Example') {\n" + + " steps {\n" + + " withFileParameter('FILE') {\n" + + " echo('foo') \n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "}"; + p.setDefinition(new CpsFlowDefinition(pipeline, true)); + WorkflowRun run = p.scheduleBuild2(0).get(); + r.waitForCompletion(run); + // definitely will fail but we just ensure parameter has been created + r.assertBuildStatus(Result.SUCCESS, run); + WorkflowRun b = p.getBuildByNumber(1); + r.assertLogContains("foo", b); + } + @Test public void base64DeclarativeParameterCreated() throws Exception { r.createSlave("remote", null, null); WorkflowJob p = r.createProject(WorkflowJob.class, "myjob"); From 1ba3a0b5ad0c5d8b4a9594b6aba560c56b086794 Mon Sep 17 00:00:00 2001 From: olivier lamy Date: Sat, 23 Jan 2021 08:19:21 +1000 Subject: [PATCH 08/34] use org.jenkins-ci.plugins:jackson2-api Signed-off-by: olivier lamy --- pom.xml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index 2ee1026..ffaa117 100644 --- a/pom.xml +++ b/pom.xml @@ -30,11 +30,6 @@ import pom - - com.fasterxml.jackson.datatype - jackson-datatype-json-org - 2.12.1 - @@ -47,6 +42,11 @@ org.jenkins-ci.plugins.workflow workflow-api + + org.jenkins-ci.plugins + jackson2-api + test + org.jenkins-ci.plugins.workflow workflow-job From 7f25496875ce13724555aafa4b98d811229bf9a1 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Sat, 23 Jan 2021 14:05:58 +1000 Subject: [PATCH 09/34] Update README.md Co-authored-by: Jesse Glick --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6a53ae9..6628fa7 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ See [JENKINS-27413](https://issues.jenkins-ci.org/browse/JENKINS-27413) and [JEN You can now declare file parameters as is in declarative pipeline: -``` +```groovy pipeline { agent any parameters { From 237e9eece7591b5a285342e9f8acecf1b386e015 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Sat, 23 Jan 2021 14:06:12 +1000 Subject: [PATCH 10/34] Update README.md Co-authored-by: Jesse Glick --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6628fa7..8a59848 100644 --- a/README.md +++ b/README.md @@ -20,8 +20,8 @@ You can now declare file parameters as is in declarative pipeline: pipeline { agent any parameters { - base64File(name: 'FILE') - stashed64File(name: 'FILE-STASH') + base64File 'FILE' + stashed64File 'FILE-STASH' } stages { stage('Example') { From ed7877d9f4119845925a358ae26032c1dc5c064b Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Sat, 23 Jan 2021 14:06:21 +1000 Subject: [PATCH 11/34] Update README.md Co-authored-by: Jesse Glick --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8a59848..ba646e3 100644 --- a/README.md +++ b/README.md @@ -29,8 +29,8 @@ pipeline { withFileParameter('FILE') { echo(/loaded '${readFile(FILE)}' from $FILE/) } - unstash "FILE-STASH" - echo(/loaded '${readFile("./FILE-STASH")}'/) + unstash 'FILE-STASH' + echo(/loaded '${readFile('FILE-STASH')}'/) } } } From ab26f20fa1e1364a62350f4c979610b80fa598cb Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Sat, 23 Jan 2021 14:07:37 +1000 Subject: [PATCH 12/34] Update src/main/java/io/jenkins/plugins/file_parameters/Base64FileParameterDefinition.java Co-authored-by: Jesse Glick --- .../plugins/file_parameters/Base64FileParameterDefinition.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/io/jenkins/plugins/file_parameters/Base64FileParameterDefinition.java b/src/main/java/io/jenkins/plugins/file_parameters/Base64FileParameterDefinition.java index c5dde18..4478c61 100644 --- a/src/main/java/io/jenkins/plugins/file_parameters/Base64FileParameterDefinition.java +++ b/src/main/java/io/jenkins/plugins/file_parameters/Base64FileParameterDefinition.java @@ -54,8 +54,7 @@ public final class Base64FileParameterDefinition extends AbstractFileParameterDe return "Base64 File Parameter"; } - @Override public String getHelpFile() - { + @Override public String getHelpFile() { return "/plugin/file-parameters/help-base64File.html"; } } From 36d2f2f8f2ebde82c51cfc5bc9acde35cbc99b4b Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Sat, 23 Jan 2021 14:09:33 +1000 Subject: [PATCH 13/34] Update README.md Co-authored-by: Jesse Glick --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ba646e3..23ca4fc 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ pipeline { stage('Example') { steps { withFileParameter('FILE') { - echo(/loaded '${readFile(FILE)}' from $FILE/) + sh 'cat $FILE' } unstash 'FILE-STASH' echo(/loaded '${readFile('FILE-STASH')}'/) From 828f0ba055915ad26b45b4e31684210c681c6769 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Sat, 23 Jan 2021 14:09:43 +1000 Subject: [PATCH 14/34] Update src/test/java/io/jenkins/plugins/file_parameters/FileParameterWrapperTest.java Co-authored-by: Jesse Glick --- .../plugins/file_parameters/FileParameterWrapperTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/io/jenkins/plugins/file_parameters/FileParameterWrapperTest.java b/src/test/java/io/jenkins/plugins/file_parameters/FileParameterWrapperTest.java index f0a2fa3..543ccfd 100644 --- a/src/test/java/io/jenkins/plugins/file_parameters/FileParameterWrapperTest.java +++ b/src/test/java/io/jenkins/plugins/file_parameters/FileParameterWrapperTest.java @@ -155,7 +155,7 @@ public class FileParameterWrapperTest { String pipeline = "pipeline {\n" + " agent any\n" + " parameters {\n" + - " stashed64File(name: 'FILE-STASH')\n" + + " stashedBase64File(name: 'FILE-STASH')\n" + " }\n" + " stages {\n" + " stage('Example') {\n" + From 1b62df5a3cb19b7cc5756a10f5d579d2a3295447 Mon Sep 17 00:00:00 2001 From: olivier lamy Date: Sat, 23 Jan 2021 14:25:44 +1000 Subject: [PATCH 15/34] fix unit test Signed-off-by: olivier lamy --- src/main/webapp/help-base64File.html | 2 +- .../plugins/file_parameters/FileParameterWrapperTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/webapp/help-base64File.html b/src/main/webapp/help-base64File.html index c12551e..3fb1a19 100644 --- a/src/main/webapp/help-base64File.html +++ b/src/main/webapp/help-base64File.html @@ -10,7 +10,7 @@ stage('Example') { steps { withFileParameter('THEFILE') { - echo(/loaded '${readFile(FILE)}' from $FILE/) + echo(/loaded '${readFile(FILE)}' from $FILE/) } } } diff --git a/src/test/java/io/jenkins/plugins/file_parameters/FileParameterWrapperTest.java b/src/test/java/io/jenkins/plugins/file_parameters/FileParameterWrapperTest.java index 543ccfd..f0a2fa3 100644 --- a/src/test/java/io/jenkins/plugins/file_parameters/FileParameterWrapperTest.java +++ b/src/test/java/io/jenkins/plugins/file_parameters/FileParameterWrapperTest.java @@ -155,7 +155,7 @@ public class FileParameterWrapperTest { String pipeline = "pipeline {\n" + " agent any\n" + " parameters {\n" + - " stashedBase64File(name: 'FILE-STASH')\n" + + " stashed64File(name: 'FILE-STASH')\n" + " }\n" + " stages {\n" + " stage('Example') {\n" + From 95584591e721a1a4d8a8a02a941fdedba382a7ab Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Sun, 24 Jan 2021 19:11:01 +1000 Subject: [PATCH 16/34] Update src/test/java/io/jenkins/plugins/file_parameters/FileParameterWrapperTest.java Co-authored-by: Jesse Glick --- .../plugins/file_parameters/FileParameterWrapperTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/io/jenkins/plugins/file_parameters/FileParameterWrapperTest.java b/src/test/java/io/jenkins/plugins/file_parameters/FileParameterWrapperTest.java index f0a2fa3..543ccfd 100644 --- a/src/test/java/io/jenkins/plugins/file_parameters/FileParameterWrapperTest.java +++ b/src/test/java/io/jenkins/plugins/file_parameters/FileParameterWrapperTest.java @@ -155,7 +155,7 @@ public class FileParameterWrapperTest { String pipeline = "pipeline {\n" + " agent any\n" + " parameters {\n" + - " stashed64File(name: 'FILE-STASH')\n" + + " stashedBase64File(name: 'FILE-STASH')\n" + " }\n" + " stages {\n" + " stage('Example') {\n" + From ece717d573f43a534b6d20bf7498ff2e2e0bd6f0 Mon Sep 17 00:00:00 2001 From: olivier lamy Date: Sun, 24 Jan 2021 19:18:13 +1000 Subject: [PATCH 17/34] more fixes after review Signed-off-by: olivier lamy --- README.md | 2 +- .../file_parameters/Base64FileParameterDefinition.java | 4 ---- .../file_parameters/StashedFileParameterDefinition.java | 9 ++------- .../Base64FileParameterDefinition/help.html} | 0 .../StashedFileParameterDefinition/help.html} | 2 +- .../file_parameters/FileParameterWrapperTest.java | 6 +++--- 6 files changed, 7 insertions(+), 16 deletions(-) rename src/main/{webapp/help-base64File.html => resources/io/jenkins/plugins/file_parameters/Base64FileParameterDefinition/help.html} (100%) rename src/main/{webapp/help-stashedFile.html => resources/io/jenkins/plugins/file_parameters/StashedFileParameterDefinition/help.html} (89%) diff --git a/README.md b/README.md index 23ca4fc..c493d49 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ pipeline { agent any parameters { base64File 'FILE' - stashed64File 'FILE-STASH' + stashedBase64File 'FILE-STASH' } stages { stage('Example') { diff --git a/src/main/java/io/jenkins/plugins/file_parameters/Base64FileParameterDefinition.java b/src/main/java/io/jenkins/plugins/file_parameters/Base64FileParameterDefinition.java index 4478c61..7b79e19 100644 --- a/src/main/java/io/jenkins/plugins/file_parameters/Base64FileParameterDefinition.java +++ b/src/main/java/io/jenkins/plugins/file_parameters/Base64FileParameterDefinition.java @@ -53,10 +53,6 @@ public final class Base64FileParameterDefinition extends AbstractFileParameterDe @Override public String getDisplayName() { return "Base64 File Parameter"; } - - @Override public String getHelpFile() { - return "/plugin/file-parameters/help-base64File.html"; - } } diff --git a/src/main/java/io/jenkins/plugins/file_parameters/StashedFileParameterDefinition.java b/src/main/java/io/jenkins/plugins/file_parameters/StashedFileParameterDefinition.java index c1b4d9c..1fc0ff3 100644 --- a/src/main/java/io/jenkins/plugins/file_parameters/StashedFileParameterDefinition.java +++ b/src/main/java/io/jenkins/plugins/file_parameters/StashedFileParameterDefinition.java @@ -47,16 +47,11 @@ public final class StashedFileParameterDefinition extends AbstractFileParameterD // TODO equals/hashCode - @Symbol("stashed64File") + @Symbol("stashedBase64File") @Extension public static final class DescriptorImpl extends ParameterDefinition.ParameterDescriptor { @Override public String getDisplayName() { - return "Stashed File Parameter"; - } - - @Override public String getHelpFile() - { - return "/plugin/file-parameters/help-stashedFile.html"; + return "Stashed Base64 File Parameter"; } } diff --git a/src/main/webapp/help-base64File.html b/src/main/resources/io/jenkins/plugins/file_parameters/Base64FileParameterDefinition/help.html similarity index 100% rename from src/main/webapp/help-base64File.html rename to src/main/resources/io/jenkins/plugins/file_parameters/Base64FileParameterDefinition/help.html diff --git a/src/main/webapp/help-stashedFile.html b/src/main/resources/io/jenkins/plugins/file_parameters/StashedFileParameterDefinition/help.html similarity index 89% rename from src/main/webapp/help-stashedFile.html rename to src/main/resources/io/jenkins/plugins/file_parameters/StashedFileParameterDefinition/help.html index b57a72d..6dd4a46 100644 --- a/src/main/webapp/help-stashedFile.html +++ b/src/main/resources/io/jenkins/plugins/file_parameters/StashedFileParameterDefinition/help.html @@ -4,7 +4,7 @@ pipeline { agent any parameters { - stashed64File(name: 'FILE-STASH') + stashedBase64File(name: 'FILE-STASH') } stages { stage('Example') { diff --git a/src/test/java/io/jenkins/plugins/file_parameters/FileParameterWrapperTest.java b/src/test/java/io/jenkins/plugins/file_parameters/FileParameterWrapperTest.java index 543ccfd..48fe23d 100644 --- a/src/test/java/io/jenkins/plugins/file_parameters/FileParameterWrapperTest.java +++ b/src/test/java/io/jenkins/plugins/file_parameters/FileParameterWrapperTest.java @@ -70,7 +70,7 @@ public class FileParameterWrapperTest { String pipeline = "pipeline {\n" + " agent any\n" + " parameters {\n" + - " base64File(name: 'FILE')\n" + + " base64File 'FILE'\n" + " }\n" + " stages {\n" + " stage('Example') {\n" + @@ -98,7 +98,7 @@ public class FileParameterWrapperTest { String pipeline = "pipeline {\n" + " agent any\n" + " parameters {\n" + - " base64File(name: 'FILE')\n" + + " base64File 'FILE'\n" + " }\n" + " stages {\n" + " stage('Example') {\n" + @@ -155,7 +155,7 @@ public class FileParameterWrapperTest { String pipeline = "pipeline {\n" + " agent any\n" + " parameters {\n" + - " stashedBase64File(name: 'FILE-STASH')\n" + + " stashedBase64File 'FILE-STASH'\n" + " }\n" + " stages {\n" + " stage('Example') {\n" + From e5ae91172270974ffee9e2f5addb777b3cee022b Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Mon, 25 Jan 2021 08:01:05 +1000 Subject: [PATCH 18/34] Update README.md Co-authored-by: Jesse Glick --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c493d49..b47449d 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ pipeline { agent any parameters { base64File 'FILE' - stashedBase64File 'FILE-STASH' + stashedFile 'FILE-STASH' } stages { stage('Example') { From ceabdb8b7283da9da27ad92cfa786d0b55fb75b4 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Mon, 25 Jan 2021 08:01:28 +1000 Subject: [PATCH 19/34] Update src/main/java/io/jenkins/plugins/file_parameters/StashedFileParameterDefinition.java Co-authored-by: Jesse Glick --- .../plugins/file_parameters/StashedFileParameterDefinition.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/io/jenkins/plugins/file_parameters/StashedFileParameterDefinition.java b/src/main/java/io/jenkins/plugins/file_parameters/StashedFileParameterDefinition.java index 1fc0ff3..3c39e93 100644 --- a/src/main/java/io/jenkins/plugins/file_parameters/StashedFileParameterDefinition.java +++ b/src/main/java/io/jenkins/plugins/file_parameters/StashedFileParameterDefinition.java @@ -47,7 +47,7 @@ public final class StashedFileParameterDefinition extends AbstractFileParameterD // TODO equals/hashCode - @Symbol("stashedBase64File") + @Symbol("stashedFile") @Extension public static final class DescriptorImpl extends ParameterDefinition.ParameterDescriptor { @Override public String getDisplayName() { From 2c2d4f5dba7ed26ef51b475990661c826fd3ac20 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Mon, 25 Jan 2021 08:03:15 +1000 Subject: [PATCH 20/34] Apply suggestions from code review Co-authored-by: Jesse Glick --- .../plugins/file_parameters/StashedFileParameterDefinition.java | 2 +- .../file_parameters/StashedFileParameterDefinition/help.html | 2 +- .../plugins/file_parameters/FileParameterWrapperTest.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/jenkins/plugins/file_parameters/StashedFileParameterDefinition.java b/src/main/java/io/jenkins/plugins/file_parameters/StashedFileParameterDefinition.java index 3c39e93..ee0f19b 100644 --- a/src/main/java/io/jenkins/plugins/file_parameters/StashedFileParameterDefinition.java +++ b/src/main/java/io/jenkins/plugins/file_parameters/StashedFileParameterDefinition.java @@ -51,7 +51,7 @@ public final class StashedFileParameterDefinition extends AbstractFileParameterD @Extension public static final class DescriptorImpl extends ParameterDefinition.ParameterDescriptor { @Override public String getDisplayName() { - return "Stashed Base64 File Parameter"; + return "Stashed File Parameter"; } } diff --git a/src/main/resources/io/jenkins/plugins/file_parameters/StashedFileParameterDefinition/help.html b/src/main/resources/io/jenkins/plugins/file_parameters/StashedFileParameterDefinition/help.html index 6dd4a46..34409b5 100644 --- a/src/main/resources/io/jenkins/plugins/file_parameters/StashedFileParameterDefinition/help.html +++ b/src/main/resources/io/jenkins/plugins/file_parameters/StashedFileParameterDefinition/help.html @@ -4,7 +4,7 @@ pipeline { agent any parameters { - stashedBase64File(name: 'FILE-STASH') + stashedFile(name: 'FILE-STASH') } stages { stage('Example') { diff --git a/src/test/java/io/jenkins/plugins/file_parameters/FileParameterWrapperTest.java b/src/test/java/io/jenkins/plugins/file_parameters/FileParameterWrapperTest.java index 48fe23d..e1ede69 100644 --- a/src/test/java/io/jenkins/plugins/file_parameters/FileParameterWrapperTest.java +++ b/src/test/java/io/jenkins/plugins/file_parameters/FileParameterWrapperTest.java @@ -155,7 +155,7 @@ public class FileParameterWrapperTest { String pipeline = "pipeline {\n" + " agent any\n" + " parameters {\n" + - " stashedBase64File 'FILE-STASH'\n" + + " stashedFile 'FILE-STASH'\n" + " }\n" + " stages {\n" + " stage('Example') {\n" + From e677d30aa0da6ccbfa185d01f5c0627a2a69adb7 Mon Sep 17 00:00:00 2001 From: olivier lamy Date: Mon, 25 Jan 2021 08:22:40 +1000 Subject: [PATCH 21/34] fix test as simplified parameter syntax do not work Signed-off-by: olivier lamy --- .../plugins/file_parameters/FileParameterWrapperTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/java/io/jenkins/plugins/file_parameters/FileParameterWrapperTest.java b/src/test/java/io/jenkins/plugins/file_parameters/FileParameterWrapperTest.java index e1ede69..12c2e83 100644 --- a/src/test/java/io/jenkins/plugins/file_parameters/FileParameterWrapperTest.java +++ b/src/test/java/io/jenkins/plugins/file_parameters/FileParameterWrapperTest.java @@ -70,7 +70,7 @@ public class FileParameterWrapperTest { String pipeline = "pipeline {\n" + " agent any\n" + " parameters {\n" + - " base64File 'FILE'\n" + + " base64File (name:'FILE')\n" + " }\n" + " stages {\n" + " stage('Example') {\n" + @@ -98,7 +98,7 @@ public class FileParameterWrapperTest { String pipeline = "pipeline {\n" + " agent any\n" + " parameters {\n" + - " base64File 'FILE'\n" + + " base64File (name: 'FILE')\n" + " }\n" + " stages {\n" + " stage('Example') {\n" + @@ -155,7 +155,7 @@ public class FileParameterWrapperTest { String pipeline = "pipeline {\n" + " agent any\n" + " parameters {\n" + - " stashedFile 'FILE-STASH'\n" + + " stashedFile (name:'FILE-STASH')\n" + " }\n" + " stages {\n" + " stage('Example') {\n" + From 292f87068afc2feae42026628b8b208c91bb888b Mon Sep 17 00:00:00 2001 From: olivier lamy Date: Mon, 25 Jan 2021 20:39:43 +1000 Subject: [PATCH 22/34] add allowNoFile option to not fail if no parameter Signed-off-by: olivier lamy --- .../file_parameters/FileParameterWrapper.java | 20 +++++++++-- .../Base64FileParameterDefinition/help.html | 21 ++++++++++++ .../FileParameterWrapperTest.java | 34 ++++++++++++++++--- 3 files changed, 68 insertions(+), 7 deletions(-) diff --git a/src/main/java/io/jenkins/plugins/file_parameters/FileParameterWrapper.java b/src/main/java/io/jenkins/plugins/file_parameters/FileParameterWrapper.java index 9855d67..b855189 100644 --- a/src/main/java/io/jenkins/plugins/file_parameters/FileParameterWrapper.java +++ b/src/main/java/io/jenkins/plugins/file_parameters/FileParameterWrapper.java @@ -41,6 +41,7 @@ import jenkins.tasks.SimpleBuildWrapper; import org.jenkinsci.Symbol; import org.kohsuke.stapler.DataBoundConstructor; +import org.kohsuke.stapler.DataBoundSetter; /** * Saves a file parameter to a temporary local file. @@ -49,22 +50,37 @@ public final class FileParameterWrapper extends SimpleBuildWrapper { public final String name; + private boolean allowNoFile; + @DataBoundConstructor public FileParameterWrapper(String name) { this.name = name; } + public boolean isAllowNoFile() { + return allowNoFile; + } + + @DataBoundSetter + public void setAllowNoFile(boolean allowNoFile) { + this.allowNoFile = allowNoFile; + } + @Override public void setUp(Context context, Run build, FilePath workspace, Launcher launcher, TaskListener listener, EnvVars initialEnvironment) throws IOException, InterruptedException { ParametersAction pa = build.getAction(ParametersAction.class); if (pa == null) { throw new AbortException("No parameters"); } ParameterValue pv = pa.getParameter(name); - if (pv == null) { + if (pv == null && !allowNoFile) { throw new AbortException("No parameter named " + name); } - if (!(pv instanceof AbstractFileParameterValue)) { + if (!(pv instanceof AbstractFileParameterValue) && !allowNoFile) { throw new AbortException("Unsupported parameter type"); } + if (pv == null && allowNoFile) { + listener.getLogger().println("Skip file parameter as there is no parameter with name: '" + name + "'"); + return; + } FilePath tempDir = WorkspaceList.tempDir(workspace); if (tempDir == null) { throw new AbortException("Missing workspace or could not make temp dir"); diff --git a/src/main/resources/io/jenkins/plugins/file_parameters/Base64FileParameterDefinition/help.html b/src/main/resources/io/jenkins/plugins/file_parameters/Base64FileParameterDefinition/help.html index 3fb1a19..b0450fd 100644 --- a/src/main/resources/io/jenkins/plugins/file_parameters/Base64FileParameterDefinition/help.html +++ b/src/main/resources/io/jenkins/plugins/file_parameters/Base64FileParameterDefinition/help.html @@ -18,3 +18,24 @@ } +
+ Per default, there will be an error if there is no parameter for the build but you can ignore this error using the + parameter attribute allowNoFile. In this case your pipeline must take into account the file doesn't exists +
+pipeline {
+  agent any
+  parameters {
+    base64File(name: 'THEFILE')
+  }
+  stages {
+    stage('Example') {
+      steps {
+        withFileParameter(name:'THEFILE', allowNoFile: true) {
+          echo(/loaded '${readFile(FILE)}' from $FILE/)
+        }
+      }
+    }
+  }
+}
+  
+
diff --git a/src/test/java/io/jenkins/plugins/file_parameters/FileParameterWrapperTest.java b/src/test/java/io/jenkins/plugins/file_parameters/FileParameterWrapperTest.java index 12c2e83..ae19416 100644 --- a/src/test/java/io/jenkins/plugins/file_parameters/FileParameterWrapperTest.java +++ b/src/test/java/io/jenkins/plugins/file_parameters/FileParameterWrapperTest.java @@ -62,8 +62,7 @@ public class FileParameterWrapperTest { r.assertLogContains("loaded 'UPLOADED CONTENT HERE' from ", b); } - @Ignore("need to implement option to tolerate undefined parameter") - @Test public void base64Undefined() throws Exception { + @Test public void base64UndefinedFail() throws Exception { r.createSlave("remote", null, null); WorkflowJob p = r.createProject(WorkflowJob.class, "myjob"); p.addProperty(new ParametersDefinitionProperty(new Base64FileParameterDefinition("FILE", null))); @@ -85,10 +84,35 @@ public class FileParameterWrapperTest { p.setDefinition(new CpsFlowDefinition(pipeline, true)); WorkflowRun run = p.scheduleBuild2(0).get(); r.waitForCompletion(run); - // definitely will fail but we just ensure parameter has been created + r.assertBuildStatus(Result.FAILURE, run); + r.assertLogContains("No parameter named FILE", run); + } + + @Test public void base64WithAllowNoFile() throws Exception { + r.createSlave("remote", null, null); + WorkflowJob p = r.createProject(WorkflowJob.class, "myjob"); + p.addProperty(new ParametersDefinitionProperty(new Base64FileParameterDefinition("FILE", null))); + String pipeline = "pipeline {\n" + + " agent any\n" + + " parameters {\n" + + " base64File (name:'FILE')\n" + + " }\n" + + " stages {\n" + + " stage('Example') {\n" + + " steps {\n" + + " withFileParameter(name:'FILE', allowNoFile: true) {\n" + + " echo('foo') \n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "}"; + p.setDefinition(new CpsFlowDefinition(pipeline, true)); + WorkflowRun run = p.scheduleBuild2(0).get(); + r.waitForCompletion(run); r.assertBuildStatus(Result.SUCCESS, run); - WorkflowRun b = p.getBuildByNumber(1); - r.assertLogContains("foo", b); + r.assertLogContains("foo", run); + r.assertLogContains("Skip file parameter as there is no parameter with name: 'FILE'", run); } @Test public void base64DeclarativeParameterCreated() throws Exception { From b960b79fa261b17d7519a3fd2cb510e902faf808 Mon Sep 17 00:00:00 2001 From: olivier lamy Date: Mon, 25 Jan 2021 20:41:27 +1000 Subject: [PATCH 23/34] option to tolerate undefined parameter has been done Signed-off-by: olivier lamy --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b47449d..e177eae 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,7 @@ pipeline { - [X] inline help text - [X] manual test - [X] automated test - - [ ] option to tolerate undefined parameter + - [X] option to tolerate undefined parameter - [ ] `input` step submission - [ ] design - [ ] manual test From b2e08aa74bb2d655c92a989c2fa191dd6fc16cf4 Mon Sep 17 00:00:00 2001 From: olivier lamy Date: Mon, 25 Jan 2021 20:42:45 +1000 Subject: [PATCH 24/34] all done for withFileParameter Signed-off-by: olivier lamy --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e177eae..2dfb925 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,7 @@ pipeline { - [X] implementation - [ ] manual test - [ ] automated test -- [ ] `withFileParameter` wrapper step +- [X] `withFileParameter` wrapper step - [X] implementation - [X] inline help text - [X] manual test From 5c29809df35ee2690a9accdcc718c1df46a3dba5 Mon Sep 17 00:00:00 2001 From: olivier lamy Date: Wed, 27 Jan 2021 11:09:50 +1000 Subject: [PATCH 25/34] add a comment on why this dependency with exclusions Signed-off-by: olivier lamy --- pom.xml | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index ffaa117..4979337 100644 --- a/pom.xml +++ b/pom.xml @@ -42,11 +42,6 @@ org.jenkins-ci.plugins.workflow workflow-api
- - org.jenkins-ci.plugins - jackson2-api - test - org.jenkins-ci.plugins.workflow workflow-job @@ -71,6 +66,13 @@ org.jenkinsci.plugins pipeline-model-definition test + + + + com.fasterxml.jackson.datatype + jackson-datatype-json-org + + From 4920a152d9304e99687944430c4948250623d5f4 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Wed, 27 Jan 2021 11:11:30 +1000 Subject: [PATCH 26/34] Update src/test/java/io/jenkins/plugins/file_parameters/FileParameterWrapperTest.java Co-authored-by: Jesse Glick --- .../plugins/file_parameters/FileParameterWrapperTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/io/jenkins/plugins/file_parameters/FileParameterWrapperTest.java b/src/test/java/io/jenkins/plugins/file_parameters/FileParameterWrapperTest.java index ae19416..a460288 100644 --- a/src/test/java/io/jenkins/plugins/file_parameters/FileParameterWrapperTest.java +++ b/src/test/java/io/jenkins/plugins/file_parameters/FileParameterWrapperTest.java @@ -69,7 +69,7 @@ public class FileParameterWrapperTest { String pipeline = "pipeline {\n" + " agent any\n" + " parameters {\n" + - " base64File (name:'FILE')\n" + + " base64File(name:'FILE')\n" + " }\n" + " stages {\n" + " stage('Example') {\n" + From 06333dcdbf169e8ff6b98446fdd5ca7d38631c60 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Wed, 27 Jan 2021 11:11:43 +1000 Subject: [PATCH 27/34] Update src/test/java/io/jenkins/plugins/file_parameters/FileParameterWrapperTest.java Co-authored-by: Jesse Glick --- .../plugins/file_parameters/FileParameterWrapperTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/io/jenkins/plugins/file_parameters/FileParameterWrapperTest.java b/src/test/java/io/jenkins/plugins/file_parameters/FileParameterWrapperTest.java index a460288..2163069 100644 --- a/src/test/java/io/jenkins/plugins/file_parameters/FileParameterWrapperTest.java +++ b/src/test/java/io/jenkins/plugins/file_parameters/FileParameterWrapperTest.java @@ -95,7 +95,7 @@ public class FileParameterWrapperTest { String pipeline = "pipeline {\n" + " agent any\n" + " parameters {\n" + - " base64File (name:'FILE')\n" + + " base64File(name:'FILE')\n" + " }\n" + " stages {\n" + " stage('Example') {\n" + From 0d3acb6e08344c799e6d72d3d4e22d20e70b8666 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Wed, 27 Jan 2021 11:12:53 +1000 Subject: [PATCH 28/34] Update src/main/resources/io/jenkins/plugins/file_parameters/Base64FileParameterDefinition/help.html Co-authored-by: Jesse Glick --- .../file_parameters/Base64FileParameterDefinition/help.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/io/jenkins/plugins/file_parameters/Base64FileParameterDefinition/help.html b/src/main/resources/io/jenkins/plugins/file_parameters/Base64FileParameterDefinition/help.html index b0450fd..a87e67e 100644 --- a/src/main/resources/io/jenkins/plugins/file_parameters/Base64FileParameterDefinition/help.html +++ b/src/main/resources/io/jenkins/plugins/file_parameters/Base64FileParameterDefinition/help.html @@ -10,7 +10,7 @@ stage('Example') { steps { withFileParameter('THEFILE') { - echo(/loaded '${readFile(FILE)}' from $FILE/) + sh 'cat $FILE' } } } From 89ee670d044d33f05c5e073e5447e732a3b2a3b7 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Wed, 27 Jan 2021 11:13:16 +1000 Subject: [PATCH 29/34] Update src/main/resources/io/jenkins/plugins/file_parameters/StashedFileParameterDefinition/help.html Co-authored-by: Jesse Glick --- .../file_parameters/StashedFileParameterDefinition/help.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/io/jenkins/plugins/file_parameters/StashedFileParameterDefinition/help.html b/src/main/resources/io/jenkins/plugins/file_parameters/StashedFileParameterDefinition/help.html index 34409b5..a1a5500 100644 --- a/src/main/resources/io/jenkins/plugins/file_parameters/StashedFileParameterDefinition/help.html +++ b/src/main/resources/io/jenkins/plugins/file_parameters/StashedFileParameterDefinition/help.html @@ -10,7 +10,7 @@ stage('Example') { steps { unstash "FILE-STASH" - echo(/loaded '${readFile("./FILE-STASH")}'/) + sh 'cat FILE-STASH' } } } From 4535fd37203874b62124d692dd332a412274e6e5 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Wed, 27 Jan 2021 11:14:40 +1000 Subject: [PATCH 30/34] Update src/test/java/io/jenkins/plugins/file_parameters/FileParameterWrapperTest.java Co-authored-by: Jesse Glick --- .../plugins/file_parameters/FileParameterWrapperTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/io/jenkins/plugins/file_parameters/FileParameterWrapperTest.java b/src/test/java/io/jenkins/plugins/file_parameters/FileParameterWrapperTest.java index 2163069..9b4a1af 100644 --- a/src/test/java/io/jenkins/plugins/file_parameters/FileParameterWrapperTest.java +++ b/src/test/java/io/jenkins/plugins/file_parameters/FileParameterWrapperTest.java @@ -179,7 +179,7 @@ public class FileParameterWrapperTest { String pipeline = "pipeline {\n" + " agent any\n" + " parameters {\n" + - " stashedFile (name:'FILE-STASH')\n" + + " stashedFile(name:'FILE-STASH')\n" + " }\n" + " stages {\n" + " stage('Example') {\n" + From be0952724d70742c20f008a987429381f3c04606 Mon Sep 17 00:00:00 2001 From: olivier lamy Date: Wed, 27 Jan 2021 11:21:38 +1000 Subject: [PATCH 31/34] remove extra empty lines Signed-off-by: olivier lamy --- .../plugins/file_parameters/Base64FileParameterDefinition.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/io/jenkins/plugins/file_parameters/Base64FileParameterDefinition.java b/src/main/java/io/jenkins/plugins/file_parameters/Base64FileParameterDefinition.java index 7b79e19..6fc3aba 100644 --- a/src/main/java/io/jenkins/plugins/file_parameters/Base64FileParameterDefinition.java +++ b/src/main/java/io/jenkins/plugins/file_parameters/Base64FileParameterDefinition.java @@ -55,6 +55,4 @@ public final class Base64FileParameterDefinition extends AbstractFileParameterDe } } - - } From 71928ff2f58f90f151f1a0ae07bdf664f2562241 Mon Sep 17 00:00:00 2001 From: olivier lamy Date: Wed, 27 Jan 2021 14:33:11 +1000 Subject: [PATCH 32/34] add allowNoFile help and move help Signed-off-by: olivier lamy --- README.md | 2 +- .../Base64FileParameterDefinition/help.html | 40 +----------------- .../FileParameterWrapper/config.jelly | 3 ++ .../help-allowNoFile.html | 3 ++ .../FileParameterWrapper/help.html | 41 +++++++++++++++++++ 5 files changed, 49 insertions(+), 40 deletions(-) create mode 100644 src/main/resources/io/jenkins/plugins/file_parameters/FileParameterWrapper/help-allowNoFile.html diff --git a/README.md b/README.md index 2dfb925..3e211ba 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ pipeline { stages { stage('Example') { steps { - withFileParameter('FILE') { + withFileParameter(name:'FILE', allowNoFile: true) { sh 'cat $FILE' } unstash 'FILE-STASH' diff --git a/src/main/resources/io/jenkins/plugins/file_parameters/Base64FileParameterDefinition/help.html b/src/main/resources/io/jenkins/plugins/file_parameters/Base64FileParameterDefinition/help.html index a87e67e..6dfe84a 100644 --- a/src/main/resources/io/jenkins/plugins/file_parameters/Base64FileParameterDefinition/help.html +++ b/src/main/resources/io/jenkins/plugins/file_parameters/Base64FileParameterDefinition/help.html @@ -1,41 +1,3 @@
-

File parameter compatible with Pipeline, how to use it in a declarative pipeline:

-
-pipeline {
-  agent any
-  parameters {
-    base64File(name: 'THEFILE')
-  }
-  stages {
-    stage('Example') {
-      steps {
-        withFileParameter('THEFILE') {
-          sh 'cat $FILE'
-        }
-      }
-    }
-  }
-}
-  
-
-
- Per default, there will be an error if there is no parameter for the build but you can ignore this error using the - parameter attribute allowNoFile. In this case your pipeline must take into account the file doesn't exists -
-pipeline {
-  agent any
-  parameters {
-    base64File(name: 'THEFILE')
-  }
-  stages {
-    stage('Example') {
-      steps {
-        withFileParameter(name:'THEFILE', allowNoFile: true) {
-          echo(/loaded '${readFile(FILE)}' from $FILE/)
-        }
-      }
-    }
-  }
-}
-  
+

File parameter compatible with Pipeline, must be used with small files

diff --git a/src/main/resources/io/jenkins/plugins/file_parameters/FileParameterWrapper/config.jelly b/src/main/resources/io/jenkins/plugins/file_parameters/FileParameterWrapper/config.jelly index f463c75..8b5f8b5 100644 --- a/src/main/resources/io/jenkins/plugins/file_parameters/FileParameterWrapper/config.jelly +++ b/src/main/resources/io/jenkins/plugins/file_parameters/FileParameterWrapper/config.jelly @@ -28,4 +28,7 @@ THE SOFTWARE. + + + diff --git a/src/main/resources/io/jenkins/plugins/file_parameters/FileParameterWrapper/help-allowNoFile.html b/src/main/resources/io/jenkins/plugins/file_parameters/FileParameterWrapper/help-allowNoFile.html new file mode 100644 index 0000000..9070737 --- /dev/null +++ b/src/main/resources/io/jenkins/plugins/file_parameters/FileParameterWrapper/help-allowNoFile.html @@ -0,0 +1,3 @@ +
+ Per default, there will be an error if there is no parameter. You can avoid failure by allowing no file. +
diff --git a/src/main/resources/io/jenkins/plugins/file_parameters/FileParameterWrapper/help.html b/src/main/resources/io/jenkins/plugins/file_parameters/FileParameterWrapper/help.html index 55e071d..d574c5b 100644 --- a/src/main/resources/io/jenkins/plugins/file_parameters/FileParameterWrapper/help.html +++ b/src/main/resources/io/jenkins/plugins/file_parameters/FileParameterWrapper/help.html @@ -2,3 +2,44 @@ Binds an (alternative) file parameter to a local file near the workspace for convenience. Parameters can be retrieved in other ways, depending on the specific parameter type. +
+

How to use it in a declarative pipeline:

+
+pipeline {
+  agent any
+  parameters {
+    base64File(name: 'THEFILE')
+  }
+  stages {
+    stage('Example') {
+      steps {
+        withFileParameter('THEFILE') {
+          sh 'cat $THEFILE'
+        }
+      }
+    }
+  }
+}
+  
+
+
+ Per default, there will be an error if there is no parameter for the build but you can ignore this error using the + parameter attribute allowNoFile. In this case your pipeline must take into account the file doesn't exists +
+pipeline {
+  agent any
+  parameters {
+    base64File(name: 'THEFILE')
+  }
+  stages {
+    stage('Example') {
+      steps {
+        withFileParameter(name:'THEFILE', allowNoFile: true) {
+          echo(/loaded '${readFile(THEFILE)}' from $THEFILE/)
+        }
+      }
+    }
+  }
+}
+  
+
From 12b668f420107aeaef291f6ae4f69c0fcac16a4d Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Wed, 27 Jan 2021 14:34:20 +1000 Subject: [PATCH 33/34] Update README.md Co-authored-by: Jesse Glick --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3e211ba..b2a2439 100644 --- a/README.md +++ b/README.md @@ -20,8 +20,8 @@ You can now declare file parameters as is in declarative pipeline: pipeline { agent any parameters { - base64File 'FILE' - stashedFile 'FILE-STASH' + base64File(name: 'FILE') + stashedFile(name: 'FILE-STASH') } stages { stage('Example') { From 405415fa6f139c5463cd71e1ed5f7fc79fed05c0 Mon Sep 17 00:00:00 2001 From: olivier lamy Date: Wed, 27 Jan 2021 14:36:00 +1000 Subject: [PATCH 34/34] stashed is for big files Signed-off-by: olivier lamy --- .../file_parameters/StashedFileParameterDefinition/help.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/io/jenkins/plugins/file_parameters/StashedFileParameterDefinition/help.html b/src/main/resources/io/jenkins/plugins/file_parameters/StashedFileParameterDefinition/help.html index a1a5500..2230c07 100644 --- a/src/main/resources/io/jenkins/plugins/file_parameters/StashedFileParameterDefinition/help.html +++ b/src/main/resources/io/jenkins/plugins/file_parameters/StashedFileParameterDefinition/help.html @@ -1,5 +1,5 @@
-

File parameter compatible with Pipeline but this one stash the file, how to use it in a declarative pipeline:

+

File parameter compatible with Pipeline but this one stash the file and must be used to handle bug files, how to use it in a declarative pipeline:

 pipeline {
   agent any