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

NPE from CopyArtifact$DescriptorImpl.doCheckProjectName when using Copy artifact from Another Project in Promotion process of a template

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Minor
    • Resolution: Fixed
    • Component/s: copyartifact-plugin
    • Labels:
      None
    • Environment:
      Jenkins 1.625.3.1
      Copy Artifact Plugin 1.37
    • Similar Issues:

      Description

      When adding a "Copy Artifact from another project" step in the promotion process in a Job Template, the server raises a NullPointerException when processing the following request:

      http://localhost:8083/job/test-template/descriptorByName/hudson.plugins.copyartifact.CopyArtifact/checkProjectName?value=
      

      The method doCheckProjectName in the CopyArtifact assume that the @AncestorInPath is not null which is a bug.

      Source code here: https://github.com/jenkinsci/copyartifact-plugin/blob/b17cbb4036e9045472cbb1b35c4b8e7ef712f375/src/main/java/hudson/plugins/copyartifact/CopyArtifact.java#L582

      How to reproduce:

      • Create a Job Template "test-job" at the root
      • Tick "Define Promotion Process"
      • "Copy Artifact from another project" action
      • An ERROR link appears

      Note: This issue does not block the functionality and this error can be ignored. Specifying an existing project and saving the configuration will make this error disappears.

        Attachments

        1. copy-artifact-error.png
          353 kB
          Allan BURDAJEWICZ
        2. copy-artifact-error.txt
          7 kB
          Allan BURDAJEWICZ

          Issue Links

            Activity

            Hide
            ikedam ikedam added a comment -

            Do you mean Templates Plugin for Job Template?

            Show
            ikedam ikedam added a comment - Do you mean Templates Plugin for Job Template?
            Hide
            allan_burdajewicz Allan BURDAJEWICZ added a comment - - edited

            Yes. Absolutely. Here are some more information.

            Issues Related

            It seems to be related to:

            The scenario is different though as this issue does not appear when configuring a "templatized job" but when configuring a Template.

            How To reproduce

            Plugins:
            [CloudBees Templates Plugin](http://documentation.cloudbees.com/docs/cje-user-guide/template.html)
            [Promoted-Builds Plugin](https://wiki.jenkins-ci.org/display/JENKINS/Promoted+Builds+Plugin)
            [Copy Artifact Plugin]https://wiki.jenkins-ci.org/display/JENKINS/Copy+Artifact+Plugin

            • Create a Job Template
            • In the `Properties` section, tick `Define Promotion Process`
            • Add the action `Copy artifacts from another project`
            • Error 500

            Possible Fix

            Seems to me that using `@AncestorInPath AbstractItem` instead of `@AncestorInPath AbstractProject` makes this work without breaking JENKINS-22856(https://issues.jenkins-ci.org/browse/JENKINS-22856).

            In the configuration of a Template

            `@AncestorInPath AbstractProject` returns null leading to the Error 500
            `@AncestorInPath AbstractItem` returns a `JobTemplate` and in the check for nearest `getParent` returns the correct `ItemGroup` element (a `Folder` if inside a folder or `Hudson` when at the root).

            In the configuration of a Templatized Job

            `@AncestorInPath AbstractProject` returns a `FreeStyleJob`
            `@AncestorInPath AbstractItem` returns a `FreeStyleJob` too.

            Maybe Daniel Beck could help us about this.

            Show
            allan_burdajewicz Allan BURDAJEWICZ added a comment - - edited Yes. Absolutely. Here are some more information. Issues Related It seems to be related to: https://issues.jenkins-ci.org/browse/JENKINS-22856 https://github.com/jenkinsci/copyartifact-plugin/pull/36 The scenario is different though as this issue does not appear when configuring a "templatized job" but when configuring a Template. How To reproduce Plugins: [CloudBees Templates Plugin] ( http://documentation.cloudbees.com/docs/cje-user-guide/template.html ) [Promoted-Builds Plugin] ( https://wiki.jenkins-ci.org/display/JENKINS/Promoted+Builds+Plugin ) [Copy Artifact Plugin] https://wiki.jenkins-ci.org/display/JENKINS/Copy+Artifact+Plugin Create a Job Template In the `Properties` section, tick `Define Promotion Process` Add the action `Copy artifacts from another project` Error 500 Possible Fix Seems to me that using `@AncestorInPath AbstractItem` instead of `@AncestorInPath AbstractProject` makes this work without breaking JENKINS-22856 ( https://issues.jenkins-ci.org/browse/JENKINS-22856 ). In the configuration of a Template `@AncestorInPath AbstractProject` returns null leading to the Error 500 `@AncestorInPath AbstractItem` returns a `JobTemplate` and in the check for nearest `getParent` returns the correct `ItemGroup` element (a `Folder` if inside a folder or `Hudson` when at the root). In the configuration of a Templatized Job `@AncestorInPath AbstractProject` returns a `FreeStyleJob` `@AncestorInPath AbstractItem` returns a `FreeStyleJob` too. Maybe Daniel Beck could help us about this.
            Hide
            ikedam ikedam added a comment -

            Thanks for the details!

            Let me see.
            Though I haven't ever used template-plugin, I imagine it works like this:

            • You can create a template project (let's call it TemplateA).
              • TemplateA never be a parent of a build, and it's never a `Job`.
            • You can create a new project from that TemplateA.
              • I believe it can be put in another folder. Let's call it /FolderB/TemplatedC .
              • /FolderB/TemplatedC can be built, and it's a `Job`.

            And problems occur in these cases:

            `anc` is used to resolve relative project names.
            `doCheckProjectName` should not resolve relative names for templates as templates can be put in another hierarchy, should it?

            Show
            ikedam ikedam added a comment - Thanks for the details! Let me see. Though I haven't ever used template-plugin, I imagine it works like this: You can create a template project (let's call it TemplateA). TemplateA never be a parent of a build, and it's never a `Job`. You can create a new project from that TemplateA. I believe it can be put in another folder. Let's call it /FolderB/TemplatedC . /FolderB/TemplatedC can be built, and it's a `Job`. And problems occur in these cases: This issue ( JENKINS-32526 ) occurs when configuring TemplateA. JENKINS-22856 occurs when configuring /FolderB/TemplatedC . `anc` is used to resolve relative project names. `doCheckProjectName` should not resolve relative names for templates as templates can be put in another hierarchy, should it?
            Hide
            ikedam ikedam added a comment -

            And why do you need promoted-builds-plugin?
            I suppose the problem occurs even when you simply add copyartifact to the builder list of the template.
            (Don't templates have builders list?)

            Show
            ikedam ikedam added a comment - And why do you need promoted-builds-plugin? I suppose the problem occurs even when you simply add copyartifact to the builder list of the template. (Don't templates have builders list?)
            Hide
            jglick Jesse Glick added a comment -

            For CloudBees folks, CJP-1524 might avoid the need for fixes like these in plugins, but at root it is a bug in Copy Artifact that it assumes that an @AncestorInPath exists. Any form validation must be written to handle the possibility of being called from an unknown context and behave gracefully.

            Show
            jglick Jesse Glick added a comment - For CloudBees folks, CJP-1524 might avoid the need for fixes like these in plugins, but at root it is a bug in Copy Artifact that it assumes that an @AncestorInPath exists. Any form validation must be written to handle the possibility of being called from an unknown context and behave gracefully.
            Hide
            scm_issue_link SCM/JIRA link daemon added a comment -

            Code changed in jenkins
            User: Allan Burdajewicz
            Path:
            src/main/java/hudson/plugins/copyartifact/CopyArtifact.java
            src/main/java/hudson/plugins/copyartifact/DownstreamBuildSelector.java
            src/main/resources/hudson/plugins/copyartifact/Messages.properties
            src/test/java/hudson/plugins/copyartifact/CopyArtifactTest.java
            src/test/java/hudson/plugins/copyartifact/DownstreamBuildSelectorTest.java
            http://jenkins-ci.org/commit/copyartifact-plugin/a34592bc7bfd3d733da7d520f6c15dbc6b728043
            Log:
            JENKINS-32526 - Handle null @AncestorInPath when selecting Jobs/Dow…

            [FIXED JENKINS-32526] - Handle null @AncestorInPath when selecting Jobs/Downstream/Upstream Jobs and for autocompletion.

            Show
            scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Allan Burdajewicz Path: src/main/java/hudson/plugins/copyartifact/CopyArtifact.java src/main/java/hudson/plugins/copyartifact/DownstreamBuildSelector.java src/main/resources/hudson/plugins/copyartifact/Messages.properties src/test/java/hudson/plugins/copyartifact/CopyArtifactTest.java src/test/java/hudson/plugins/copyartifact/DownstreamBuildSelectorTest.java http://jenkins-ci.org/commit/copyartifact-plugin/a34592bc7bfd3d733da7d520f6c15dbc6b728043 Log: JENKINS-32526 - Handle null @AncestorInPath when selecting Jobs/Dow… [FIXED JENKINS-32526] - Handle null @AncestorInPath when selecting Jobs/Downstream/Upstream Jobs and for autocompletion.
            Hide
            ikedam ikedam added a comment -

            Released 1.38 containing this fix.
            It will be available in the update center in a day.

            Show
            ikedam ikedam added a comment - Released 1.38 containing this fix. It will be available in the update center in a day.

              People

              • Assignee:
                allan_burdajewicz Allan BURDAJEWICZ
                Reporter:
                allan_burdajewicz Allan BURDAJEWICZ
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: