Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-30357

CopyArtifact step fails when using ParameterizedBuildSelector class for selecting build

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • copyartifact-plugin
    • Jenkins 1.627
      WorkFlow 1.10

      This is error i got when trying to use copy artifact with build selector parameter. Using last successful is fine.
      java.lang.NullPointerException
      at java.io.StringReader.<init>(StringReader.java:50)
      at com.thoughtworks.xstream.XStream.fromXML(XStream.java:1035)
      at hudson.plugins.copyartifact.BuildSelectorParameter.getSelectorFromXml(BuildSelectorParameter.java:87)
      at hudson.plugins.copyartifact.ParameterizedBuildSelector.getBuild(ParameterizedBuildSelector.java:52)
      at hudson.plugins.copyartifact.CopyArtifact.perform(CopyArtifact.java:354)
      at org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:68)
      at org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:59)
      at org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution$1$1.call(AbstractSynchronousNonBlockingStepExecution.java:49)
      at hudson.security.ACL.impersonate(ACL.java:213)
      at org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution$1.run(AbstractSynchronousNonBlockingStepExecution.java:47)
      at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
      at java.util.concurrent.FutureTask.run(FutureTask.java:262)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
      at java.lang.Thread.run(Thread.java:745)
      Finished: FAILURE

          [JENKINS-30357] CopyArtifact step fails when using ParameterizedBuildSelector class for selecting build

          ikedam added a comment -

          Though I haven't tested that yet, I don't think Run#getEnvironment(TaskListener) resolved the problem as it doesn't extract variables from ParametersAction.
          I think I have to resolve this in a following way:

          • Make ParameterizedBuildSelector accepts also immediate values.
            • It's good to implement this as a fallback when failed to resolve the variable.
          • Update the configuration to pass not the variable name (VARNAME) but the variable value ${VARNAME)

          ikedam added a comment - Though I haven't tested that yet, I don't think Run#getEnvironment(TaskListener) resolved the problem as it doesn't extract variables from ParametersAction . I think I have to resolve this in a following way: Make ParameterizedBuildSelector accepts also immediate values. It's good to implement this as a fallback when failed to resolve the variable. Update the configuration to pass not the variable name ( VARNAME ) but the variable value ${VARNAME )

          Jesse Glick added a comment -

          I don't think Run#getEnvironment(TaskListener) resolved the problem as it doesn't extract variables from ParametersAction

          Ah, true, this code is located elsewhere. Still, the code I pointed to should be fixed, it would just not help in this case. So actually ParameterizedBuildSelector ought to ignore env and instead ask parent for ParametersAction. (Currently ParametersAction.buildEnvVars does not offer a Run overload but it can be trivially inlined, as I do in the code above.) And of course it should gracefully handle the case that there is no such parameter; rather than throwing an NPE, throw a meaningful exception, or return null. (Fallbacks here are a poor idea since parameters already have default values.)

          Anyway there is no purpose in using ParameterizedBuildSelector from a Workflow to begin with that I can see. Use SpecificBuildSelector and use logic in your script to pass a desired number rather than a string constant.

          Jesse Glick added a comment - I don't think Run#getEnvironment(TaskListener) resolved the problem as it doesn't extract variables from ParametersAction Ah, true, this code is located elsewhere. Still, the code I pointed to should be fixed, it would just not help in this case. So actually ParameterizedBuildSelector ought to ignore env and instead ask parent for ParametersAction . (Currently ParametersAction.buildEnvVars does not offer a Run overload but it can be trivially inlined, as I do in the code above.) And of course it should gracefully handle the case that there is no such parameter; rather than throwing an NPE, throw a meaningful exception, or return null. (Fallbacks here are a poor idea since parameters already have default values.) Anyway there is no purpose in using ParameterizedBuildSelector from a Workflow to begin with that I can see. Use SpecificBuildSelector and use logic in your script to pass a desired number rather than a string constant.

          ikedam added a comment -

          ikedam added a comment - https://github.com/jenkinsci/copyartifact-plugin/pull/70

          Code changed in jenkins
          User: ikedam
          Path:
          src/test/java/hudson/plugins/copyartifact/ParameterizedBuildSelectorTest.java
          http://jenkins-ci.org/commit/copyartifact-plugin/bab56aae014bf259755fdb3d966dac0be35382b3
          Log:
          JENKINS-30357 Added tests to reproduce JENKINS-30357, NPE when ParameterizedBuildSelector in workflow, or using an undefined variable.

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: ikedam Path: src/test/java/hudson/plugins/copyartifact/ParameterizedBuildSelectorTest.java http://jenkins-ci.org/commit/copyartifact-plugin/bab56aae014bf259755fdb3d966dac0be35382b3 Log: JENKINS-30357 Added tests to reproduce JENKINS-30357 , NPE when ParameterizedBuildSelector in workflow, or using an undefined variable.

          Code changed in jenkins
          User: ikedam
          Path:
          src/main/java/hudson/plugins/copyartifact/CopyArtifact.java
          src/main/java/hudson/plugins/copyartifact/ParameterizedBuildSelector.java
          http://jenkins-ci.org/commit/copyartifact-plugin/6ddc88a0e0609bde83d8aecbd90170f254cc8fcf
          Log:
          JENKINS-30357 Fixed NPE when using ParameterizedBuildSelector in Workflow or using undefined variables in ParameterizedBuildSelector.

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: ikedam Path: src/main/java/hudson/plugins/copyartifact/CopyArtifact.java src/main/java/hudson/plugins/copyartifact/ParameterizedBuildSelector.java http://jenkins-ci.org/commit/copyartifact-plugin/6ddc88a0e0609bde83d8aecbd90170f254cc8fcf Log: JENKINS-30357 Fixed NPE when using ParameterizedBuildSelector in Workflow or using undefined variables in ParameterizedBuildSelector.

          Code changed in jenkins
          User: ikedam
          Path:
          src/main/java/hudson/plugins/copyartifact/ParameterizedBuildSelector.java
          src/test/java/hudson/plugins/copyartifact/ParameterizedBuildSelectorTest.java
          http://jenkins-ci.org/commit/copyartifact-plugin/4e6cb78a2226ffe238a25ddfa788866c8cb4f131
          Log:
          [FIXED JENKINS-30357] Improved error handlings in ParameterizedBuildSelector.

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: ikedam Path: src/main/java/hudson/plugins/copyartifact/ParameterizedBuildSelector.java src/test/java/hudson/plugins/copyartifact/ParameterizedBuildSelectorTest.java http://jenkins-ci.org/commit/copyartifact-plugin/4e6cb78a2226ffe238a25ddfa788866c8cb4f131 Log: [FIXED JENKINS-30357] Improved error handlings in ParameterizedBuildSelector.

          Code changed in jenkins
          User: ikedam
          Path:
          src/main/java/hudson/plugins/copyartifact/ParameterizedBuildSelector.java
          src/main/resources/hudson/plugins/copyartifact/ParameterizedBuildSelector/help-parameterName.html
          src/test/java/hudson/plugins/copyartifact/ParameterizedBuildSelectorTest.java
          http://jenkins-ci.org/commit/copyartifact-plugin/43699c2f605172202f228d627a4cb329dc95f984
          Log:
          JENKINS-30357 Extends ParameterizedBuildSelector to also accepts immediate values (<Selector />) and variable expressions (${SELECTOR}).

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: ikedam Path: src/main/java/hudson/plugins/copyartifact/ParameterizedBuildSelector.java src/main/resources/hudson/plugins/copyartifact/ParameterizedBuildSelector/help-parameterName.html src/test/java/hudson/plugins/copyartifact/ParameterizedBuildSelectorTest.java http://jenkins-ci.org/commit/copyartifact-plugin/43699c2f605172202f228d627a4cb329dc95f984 Log: JENKINS-30357 Extends ParameterizedBuildSelector to also accepts immediate values (<Selector />) and variable expressions (${SELECTOR}).

          Code changed in jenkins
          User: ikedam
          Path:
          src/test/java/hudson/plugins/copyartifact/ParameterizedBuildSelectorTest.java
          http://jenkins-ci.org/commit/copyartifact-plugin/d7df521bde6fe4dae57ad16c962e1957435b70e1
          Log:
          JENKINS-30357 Fixed failing tests.

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: ikedam Path: src/test/java/hudson/plugins/copyartifact/ParameterizedBuildSelectorTest.java http://jenkins-ci.org/commit/copyartifact-plugin/d7df521bde6fe4dae57ad16c962e1957435b70e1 Log: JENKINS-30357 Fixed failing tests.

          Code changed in jenkins
          User: ikedam
          Path:
          src/main/java/hudson/plugins/copyartifact/CopyArtifact.java
          src/main/java/hudson/plugins/copyartifact/ParameterizedBuildSelector.java
          src/main/resources/hudson/plugins/copyartifact/ParameterizedBuildSelector/help-parameterName.html
          src/test/java/hudson/plugins/copyartifact/ParameterizedBuildSelectorTest.java
          http://jenkins-ci.org/commit/copyartifact-plugin/b72f3f9c95d656ff72ead97ffce7e94684d38571
          Log:
          Merge pull request #70 from ikedam/feature/JENKINS-30357_NpeInParameterizedBuildSelector

          JENKINS-30357 Fixed NPE and other improvements in ParameterizedBuildSelector

          Compare: https://github.com/jenkinsci/copyartifact-plugin/compare/f4946461e5f4...b72f3f9c95d6

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: ikedam Path: src/main/java/hudson/plugins/copyartifact/CopyArtifact.java src/main/java/hudson/plugins/copyartifact/ParameterizedBuildSelector.java src/main/resources/hudson/plugins/copyartifact/ParameterizedBuildSelector/help-parameterName.html src/test/java/hudson/plugins/copyartifact/ParameterizedBuildSelectorTest.java http://jenkins-ci.org/commit/copyartifact-plugin/b72f3f9c95d656ff72ead97ffce7e94684d38571 Log: Merge pull request #70 from ikedam/feature/ JENKINS-30357 _NpeInParameterizedBuildSelector JENKINS-30357 Fixed NPE and other improvements in ParameterizedBuildSelector Compare: https://github.com/jenkinsci/copyartifact-plugin/compare/f4946461e5f4...b72f3f9c95d6

          ikedam added a comment -

          Fixed in copyartifact-1.36.1.
          It will be available in the update center in a day.
          Please try that.

          ikedam added a comment - Fixed in copyartifact-1.36.1. It will be available in the update center in a day. Please try that.

            ikedam ikedam
            tomaxsas Tomas Zaleniakas
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: