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

CopyArtifact step fails when using ParameterizedBuildSelector class for selecting build

    Details

    • Similar Issues:

      Description

      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

        Attachments

          Issue Links

            Activity

            Hide
            jglick 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.

            Show
            jglick 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 .
            Hide
            ikedam 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)
            Show
            ikedam 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 )
            Hide
            jglick 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.

            Show
            jglick 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.
            Show
            ikedam ikedam added a comment - https://github.com/jenkinsci/copyartifact-plugin/pull/70
            Hide
            scm_issue_link 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.

            Show
            scm_issue_link 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.
            Hide
            scm_issue_link 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.

            Show
            scm_issue_link 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.
            Hide
            scm_issue_link 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.

            Show
            scm_issue_link 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.
            Hide
            scm_issue_link 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}).

            Show
            scm_issue_link 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}).
            Hide
            scm_issue_link 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.

            Show
            scm_issue_link 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.
            Hide
            scm_issue_link 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

            Show
            scm_issue_link 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
            Hide
            ikedam ikedam added a comment -

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

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

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved: