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

          Tomas Zaleniakas created issue -
          Jesse Glick made changes -
          Component/s New: copyartifact-plugin [ 15692 ]
          Component/s Original: workflow-plugin [ 18820 ]
          Assignee Original: Jesse Glick [ jglick ]
          Labels New: workflow

          Jesse Glick added a comment -

          env.get(parameterName) is returning null (and the plugin does no proper error reporting). This code is wrong, as Run.getEnvironment(TaskListener) is available even for WorkflowRun.

          Jesse Glick added a comment - env.get(parameterName) is returning null (and the plugin does no proper error reporting). This code is wrong, as Run.getEnvironment(TaskListener) is available even for WorkflowRun .
          Jesse Glick made changes -
          Link New: This issue is blocking JENKINS-24887 [ JENKINS-24887 ]
          ikedam made changes -
          Link New: This issue is related to JENKINS-26694 [ JENKINS-26694 ]

          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 )
          ikedam made changes -
          Assignee New: ikedam [ ikedam ]

          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 made changes -
          Status Original: Open [ 1 ] New: In Progress [ 3 ]

          ikedam added a comment -

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

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

              Created:
              Updated:
              Resolved: