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

Copy artifact fails on first pipeline run with buildParameter selector

    • Icon: Bug Bug
    • Resolution: Won't Fix
    • Icon: Major Major
    • None
    • Jenkins 2.150.2
      Copy Artifact 1.41
      Pipeline 1.11.1 (also tested with 1.10.2)

      We have a job which uses a multibranch pipeline and copies from another job, based on a parameter. In the pipeline, it is expected that the default parameter (which is lastSuccessfulBuild) will be used (the parameter is for cases that the Jenkinsfile is used elsewhere).

      When the branch is newly created, the copy fails with ERROR: Unable to find a build for artifact copy from: UPSTREAM_PROJECT.  (This same error occurs when the parameters are manually removed and the job is rerun.)

      The defaults are used to set params, which was fixed in JENKINS-35698, but they don't appear to be used for copy artifact.

       

      In a test case, a job UPSTREAM_PROJECT  was created with a single artifact.  A scripted pipeline build was created to pull from that job and print the parameters.  It uses a properties block to create the parameter and  perform the copy.  On the first run, it falls and on subsequent runs it succeeds.

      The copy project pipeline:

      properties([
        parameters([
          [$class: 'BuildSelectorParameter', defaultSelector: lastSuccessful(), description: 'Upstream project', name: 'UPSTREAM'],
        ])
      ])
      node {
        print params
        print buildParameter('UPSTREAM')
        copyArtifacts fingerprintArtifacts: false, flatten: true, projectName: 'UPSTREAM_PROJECT', selector: buildParameter('UPSTREAM')
      }

        

      Return from the first build (that fails, started with Build):

      Started by user MY_USER
      Running in Durability level: MAX_SURVIVABILITY
      [Pipeline] Start of Pipeline
      [Pipeline] properties
      [Pipeline] node
      Running on Ubuntu 16.04 (i-09db975617c73099c) in /home/ubuntu/workspace/Test
      [Pipeline] {
      [Pipeline] echo
      {UPSTREAM=<StatusBuildSelector plugin="copyartifact@1.41"/>}
      [Pipeline] echo
      @buildParameter(<anonymous>=UPSTREAM)
      [Pipeline] copyArtifacts
      [Pipeline] }
      [Pipeline] // node
      [Pipeline] End of Pipeline
      ERROR: Unable to find a build for artifact copy from: UPSTREAM_PROJECT
      Finished: FAILURE

       

      Return from the second build (that works, started with Build With Parameters and defaults):

      Started by user MY_USER
      Running in Durability level: MAX_SURVIVABILITY
      [Pipeline] Start of Pipeline
      [Pipeline] properties
      [Pipeline] node
      Running on Ubuntu 16.04 (i-09db975617c73099c) in /home/ubuntu/workspace/Test
      [Pipeline] {
      [Pipeline] echo
      {UPSTREAM=<StatusBuildSelector plugin="copyartifact@1.41"/>, BUILD_TYPE=Release, STRING=string, BOOLEAN=true}
      [Pipeline] echo
      @buildParameter(<anonymous>=UPSTREAM)
      [Pipeline] copyArtifacts
      Copied 1 artifact from "UPSTREAM_PROJECT" build number 2
      [Pipeline] }
      [Pipeline] // node
      [Pipeline] End of Pipeline
      Finished: SUCCESS

      ---------

          [JENKINS-56149] Copy artifact fails on first pipeline run with buildParameter selector

          Ryan Desmond created issue -
          Ryan Desmond made changes -
          Description Original: We have a job which uses a multibranch pipeline and copies from another job, based on a parameter. In the pipeline, it is expected that the default parameter (which is {{lastSuccessfulBuild}}) will do the right thing (the parameter is for cases that the Jenkinsfile is used elsewhere).

          When the branch is newly created, the copy fails with {{ERROR: Unable to find a build for artifact copy from: UPSTREAM_PROJECT}}. (This same error occurs when the parameters are manually removed

          The defaults are used to set {{params}}, which was fixed in JENKINS-35698, but they don't appear to be used for copy artifact.

          The copy project pipeline:
          --------
          properties([
              parameters([
                  [$class: 'BuildSelectorParameter', defaultSelector: lastSuccessful(), description: 'Upstream project', name: 'UPSTREAM'],
              ])
          ])

          node {
              print params
              print buildParameter('UPSTREAM')
              copyArtifacts fingerprintArtifacts: false, flatten: true, projectName: 'UPSTREAM_PROJECT', selector: buildParameter('UPSTREAM')
          -------

          Return from the first build (that fails, started with Build):
          -------
          Started by user MY_USER
          Running in Durability level: MAX_SURVIVABILITY
          [Pipeline] Start of Pipeline
          [Pipeline] properties
          [Pipeline] node
          Running on Ubuntu 16.04 (i-09db975617c73099c) in /home/ubuntu/workspace/Test
          [Pipeline] {
          [Pipeline] echo
          {UPSTREAM=<StatusBuildSelector plugin="copyartifact@1.41"/>}
          [Pipeline] echo
          @buildParameter(<anonymous>=UPSTREAM)
          [Pipeline] copyArtifacts
          [Pipeline] }
          [Pipeline] // node
          [Pipeline] End of Pipeline
          ERROR: Unable to find a build for artifact copy from: UPSTREAM_PROJECT
          Finished: FAILURE
          -------

          Return from the second build (that works, started with Build With Parameters and defaults):
          -------
          Started by user MY_USER
          Running in Durability level: MAX_SURVIVABILITY
          [Pipeline] Start of Pipeline
          [Pipeline] properties
          [Pipeline] node
          Running on Ubuntu 16.04 (i-09db975617c73099c) in /home/ubuntu/workspace/Test
          [Pipeline] {
          [Pipeline] echo
          {UPSTREAM=<StatusBuildSelector plugin="copyartifact@1.41"/>}
          [Pipeline] echo
          @buildParameter(<anonymous>=UPSTREAM)
          [Pipeline] copyArtifacts
          Copied 1 artifact from "UPSTREAM_PROJECT" build number 2
          [Pipeline] }
          [Pipeline] // node
          [Pipeline] End of Pipeline
          Finished: SUCCESS
          ---------
          New: We have a job which uses a multibranch pipeline and copies from another job, based on a parameter. In the pipeline, it is expected that the default parameter (which is {{lastSuccessfulBuild}}) will do the right thing (the parameter is for cases that the Jenkinsfile is used elsewhere).

          When the branch is newly created, the copy fails with {{ERROR: Unable to find a build for artifact copy from: UPSTREAM_PROJECT}}. (This same error occurs when the parameters are manually removed

          The defaults are used to set {{params}}, which was fixed in JENKINS-35698, but they don't appear to be used for copy artifact.

          {{The copy project pipeline:}}
          {code:java}
          properties([
            parameters([
              [$class: 'BuildSelectorParameter', defaultSelector: lastSuccessful(), description: 'Upstream project', name: 'UPSTREAM'],
            ])
          ])
          node {
            print params
            print buildParameter('UPSTREAM')
            copyArtifacts fingerprintArtifacts: false, flatten: true, projectName: 'UPSTREAM_PROJECT', selector: buildParameter('UPSTREAM')
          }{code}
           

           

          Return from the first build (that fails, started with Build):
          {code:java}
          Started by user MY_USER
          Running in Durability level: MAX_SURVIVABILITY
          [Pipeline] Start of Pipeline
          [Pipeline] properties
          [Pipeline] node
          Running on Ubuntu 16.04 (i-09db975617c73099c) in /home/ubuntu/workspace/Test
          [Pipeline] {
          [Pipeline] echo
          {UPSTREAM=<StatusBuildSelector plugin="copyartifact@1.41"/>}
          [Pipeline] echo
          @buildParameter(<anonymous>=UPSTREAM)
          [Pipeline] copyArtifacts
          [Pipeline] }
          [Pipeline] // node
          [Pipeline] End of Pipeline
          ERROR: Unable to find a build for artifact copy from: UPSTREAM_PROJECT
          Finished: FAILURE{code}

           
          Return from the second build (that works, started with Build With Parameters and defaults):
          {code:java}
          Started by user MY_USER
          Running in Durability level: MAX_SURVIVABILITY
          [Pipeline] Start of Pipeline
          [Pipeline] properties
          [Pipeline] node
          Running on Ubuntu 16.04 (i-09db975617c73099c) in /home/ubuntu/workspace/Test
          [Pipeline] {
          [Pipeline] echo
          {UPSTREAM=<StatusBuildSelector plugin="copyartifact@1.41"/>, BUILD_TYPE=Release, STRING=string, BOOLEAN=true}
          [Pipeline] echo
          @buildParameter(<anonymous>=UPSTREAM)
          [Pipeline] copyArtifacts
          Copied 1 artifact from "UPSTREAM_PROJECT" build number 2
          [Pipeline] }
          [Pipeline] // node
          [Pipeline] End of Pipeline
          Finished: SUCCESS{code}

          ---------
          Ryan Desmond made changes -
          Description Original: We have a job which uses a multibranch pipeline and copies from another job, based on a parameter. In the pipeline, it is expected that the default parameter (which is {{lastSuccessfulBuild}}) will do the right thing (the parameter is for cases that the Jenkinsfile is used elsewhere).

          When the branch is newly created, the copy fails with {{ERROR: Unable to find a build for artifact copy from: UPSTREAM_PROJECT}}. (This same error occurs when the parameters are manually removed

          The defaults are used to set {{params}}, which was fixed in JENKINS-35698, but they don't appear to be used for copy artifact.

          {{The copy project pipeline:}}
          {code:java}
          properties([
            parameters([
              [$class: 'BuildSelectorParameter', defaultSelector: lastSuccessful(), description: 'Upstream project', name: 'UPSTREAM'],
            ])
          ])
          node {
            print params
            print buildParameter('UPSTREAM')
            copyArtifacts fingerprintArtifacts: false, flatten: true, projectName: 'UPSTREAM_PROJECT', selector: buildParameter('UPSTREAM')
          }{code}
           

           

          Return from the first build (that fails, started with Build):
          {code:java}
          Started by user MY_USER
          Running in Durability level: MAX_SURVIVABILITY
          [Pipeline] Start of Pipeline
          [Pipeline] properties
          [Pipeline] node
          Running on Ubuntu 16.04 (i-09db975617c73099c) in /home/ubuntu/workspace/Test
          [Pipeline] {
          [Pipeline] echo
          {UPSTREAM=<StatusBuildSelector plugin="copyartifact@1.41"/>}
          [Pipeline] echo
          @buildParameter(<anonymous>=UPSTREAM)
          [Pipeline] copyArtifacts
          [Pipeline] }
          [Pipeline] // node
          [Pipeline] End of Pipeline
          ERROR: Unable to find a build for artifact copy from: UPSTREAM_PROJECT
          Finished: FAILURE{code}

           
          Return from the second build (that works, started with Build With Parameters and defaults):
          {code:java}
          Started by user MY_USER
          Running in Durability level: MAX_SURVIVABILITY
          [Pipeline] Start of Pipeline
          [Pipeline] properties
          [Pipeline] node
          Running on Ubuntu 16.04 (i-09db975617c73099c) in /home/ubuntu/workspace/Test
          [Pipeline] {
          [Pipeline] echo
          {UPSTREAM=<StatusBuildSelector plugin="copyartifact@1.41"/>, BUILD_TYPE=Release, STRING=string, BOOLEAN=true}
          [Pipeline] echo
          @buildParameter(<anonymous>=UPSTREAM)
          [Pipeline] copyArtifacts
          Copied 1 artifact from "UPSTREAM_PROJECT" build number 2
          [Pipeline] }
          [Pipeline] // node
          [Pipeline] End of Pipeline
          Finished: SUCCESS{code}

          ---------
          New: We have a job which uses a multibranch pipeline and copies from another job, based on a parameter. In the pipeline, it is expected that the default parameter (which is {{lastSuccessfulBuild}}) will do the right thing (the parameter is for cases that the Jenkinsfile is used elsewhere).

          When the branch is newly created, the copy fails with {{ERROR: Unable to find a build for artifact copy from: UPSTREAM_PROJECT}}. (This same error occurs when the parameters are manually removed

          The defaults are used to set {{params}}, which was fixed in JENKINS-35698, but they don't appear to be used for copy artifact.

           

          {{The copy project pipeline:}}
          {code:java}
          properties([
            parameters([
              [$class: 'BuildSelectorParameter', defaultSelector: lastSuccessful(), description: 'Upstream project', name: 'UPSTREAM'],
            ])
          ])
          node {
            print params
            print buildParameter('UPSTREAM')
            copyArtifacts fingerprintArtifacts: false, flatten: true, projectName: 'UPSTREAM_PROJECT', selector: buildParameter('UPSTREAM')
          }{code}
            

          Return from the first build (that fails, started with Build):
          {code:java}
          Started by user MY_USER
          Running in Durability level: MAX_SURVIVABILITY
          [Pipeline] Start of Pipeline
          [Pipeline] properties
          [Pipeline] node
          Running on Ubuntu 16.04 (i-09db975617c73099c) in /home/ubuntu/workspace/Test
          [Pipeline] {
          [Pipeline] echo
          {UPSTREAM=<StatusBuildSelector plugin="copyartifact@1.41"/>}
          [Pipeline] echo
          @buildParameter(<anonymous>=UPSTREAM)
          [Pipeline] copyArtifacts
          [Pipeline] }
          [Pipeline] // node
          [Pipeline] End of Pipeline
          ERROR: Unable to find a build for artifact copy from: UPSTREAM_PROJECT
          Finished: FAILURE{code}
           

          Return from the second build (that works, started with Build With Parameters and defaults):
          {code:java}
          Started by user MY_USER
          Running in Durability level: MAX_SURVIVABILITY
          [Pipeline] Start of Pipeline
          [Pipeline] properties
          [Pipeline] node
          Running on Ubuntu 16.04 (i-09db975617c73099c) in /home/ubuntu/workspace/Test
          [Pipeline] {
          [Pipeline] echo
          {UPSTREAM=<StatusBuildSelector plugin="copyartifact@1.41"/>, BUILD_TYPE=Release, STRING=string, BOOLEAN=true}
          [Pipeline] echo
          @buildParameter(<anonymous>=UPSTREAM)
          [Pipeline] copyArtifacts
          Copied 1 artifact from "UPSTREAM_PROJECT" build number 2
          [Pipeline] }
          [Pipeline] // node
          [Pipeline] End of Pipeline
          Finished: SUCCESS{code}
          ---------
          Ryan Desmond made changes -
          Description Original: We have a job which uses a multibranch pipeline and copies from another job, based on a parameter. In the pipeline, it is expected that the default parameter (which is {{lastSuccessfulBuild}}) will do the right thing (the parameter is for cases that the Jenkinsfile is used elsewhere).

          When the branch is newly created, the copy fails with {{ERROR: Unable to find a build for artifact copy from: UPSTREAM_PROJECT}}. (This same error occurs when the parameters are manually removed

          The defaults are used to set {{params}}, which was fixed in JENKINS-35698, but they don't appear to be used for copy artifact.

           

          {{The copy project pipeline:}}
          {code:java}
          properties([
            parameters([
              [$class: 'BuildSelectorParameter', defaultSelector: lastSuccessful(), description: 'Upstream project', name: 'UPSTREAM'],
            ])
          ])
          node {
            print params
            print buildParameter('UPSTREAM')
            copyArtifacts fingerprintArtifacts: false, flatten: true, projectName: 'UPSTREAM_PROJECT', selector: buildParameter('UPSTREAM')
          }{code}
            

          Return from the first build (that fails, started with Build):
          {code:java}
          Started by user MY_USER
          Running in Durability level: MAX_SURVIVABILITY
          [Pipeline] Start of Pipeline
          [Pipeline] properties
          [Pipeline] node
          Running on Ubuntu 16.04 (i-09db975617c73099c) in /home/ubuntu/workspace/Test
          [Pipeline] {
          [Pipeline] echo
          {UPSTREAM=<StatusBuildSelector plugin="copyartifact@1.41"/>}
          [Pipeline] echo
          @buildParameter(<anonymous>=UPSTREAM)
          [Pipeline] copyArtifacts
          [Pipeline] }
          [Pipeline] // node
          [Pipeline] End of Pipeline
          ERROR: Unable to find a build for artifact copy from: UPSTREAM_PROJECT
          Finished: FAILURE{code}
           

          Return from the second build (that works, started with Build With Parameters and defaults):
          {code:java}
          Started by user MY_USER
          Running in Durability level: MAX_SURVIVABILITY
          [Pipeline] Start of Pipeline
          [Pipeline] properties
          [Pipeline] node
          Running on Ubuntu 16.04 (i-09db975617c73099c) in /home/ubuntu/workspace/Test
          [Pipeline] {
          [Pipeline] echo
          {UPSTREAM=<StatusBuildSelector plugin="copyartifact@1.41"/>, BUILD_TYPE=Release, STRING=string, BOOLEAN=true}
          [Pipeline] echo
          @buildParameter(<anonymous>=UPSTREAM)
          [Pipeline] copyArtifacts
          Copied 1 artifact from "UPSTREAM_PROJECT" build number 2
          [Pipeline] }
          [Pipeline] // node
          [Pipeline] End of Pipeline
          Finished: SUCCESS{code}
          ---------
          New: We have a job which uses a multibranch pipeline and copies from another job, based on a parameter. In the pipeline, it is expected that the default parameter (which is {{lastSuccessfulBuild}}) will be used (the parameter is for cases that the Jenkinsfile is used elsewhere).

          When the branch is newly created, the copy fails with {{ERROR: Unable to find a build for artifact copy from: UPSTREAM_PROJECT}}.  (This same error occurs when the parameters are manually removed and the job is rerun.)

          The defaults are used to set {{params}}, which was fixed in JENKINS-35698, but they don't appear to be used for copy artifact.

           

          In a test case, a job UPSTREAM_PROJECT  was created with a single artifact.  A scripted pipeline build was created to pull from that job and print the parameters.  It uses a properties block to create the parameter and  perform the copy.  On the first run, it falls and on subsequent runs it succeeds.

          {{The copy project pipeline:}}
          {code:java}
          properties([
            parameters([
              [$class: 'BuildSelectorParameter', defaultSelector: lastSuccessful(), description: 'Upstream project', name: 'UPSTREAM'],
            ])
          ])
          node {
            print params
            print buildParameter('UPSTREAM')
            copyArtifacts fingerprintArtifacts: false, flatten: true, projectName: 'UPSTREAM_PROJECT', selector: buildParameter('UPSTREAM')
          }{code}
            

          Return from the first build (that fails, started with Build):
          {code:java}
          Started by user MY_USER
          Running in Durability level: MAX_SURVIVABILITY
          [Pipeline] Start of Pipeline
          [Pipeline] properties
          [Pipeline] node
          Running on Ubuntu 16.04 (i-09db975617c73099c) in /home/ubuntu/workspace/Test
          [Pipeline] {
          [Pipeline] echo
          {UPSTREAM=<StatusBuildSelector plugin="copyartifact@1.41"/>}
          [Pipeline] echo
          @buildParameter(<anonymous>=UPSTREAM)
          [Pipeline] copyArtifacts
          [Pipeline] }
          [Pipeline] // node
          [Pipeline] End of Pipeline
          ERROR: Unable to find a build for artifact copy from: UPSTREAM_PROJECT
          Finished: FAILURE{code}
           

          Return from the second build (that works, started with Build With Parameters and defaults):
          {code:java}
          Started by user MY_USER
          Running in Durability level: MAX_SURVIVABILITY
          [Pipeline] Start of Pipeline
          [Pipeline] properties
          [Pipeline] node
          Running on Ubuntu 16.04 (i-09db975617c73099c) in /home/ubuntu/workspace/Test
          [Pipeline] {
          [Pipeline] echo
          {UPSTREAM=<StatusBuildSelector plugin="copyartifact@1.41"/>, BUILD_TYPE=Release, STRING=string, BOOLEAN=true}
          [Pipeline] echo
          @buildParameter(<anonymous>=UPSTREAM)
          [Pipeline] copyArtifacts
          Copied 1 artifact from "UPSTREAM_PROJECT" build number 2
          [Pipeline] }
          [Pipeline] // node
          [Pipeline] End of Pipeline
          Finished: SUCCESS{code}
          ---------

          ikedam added a comment -

          Pass the parameter value, not the parameter name, like:

          selector: buildParameter(params.UPSTREAM)
          

          Please also see the help of parameterName:
          https://github.com/jenkinsci/copyartifact-plugin/blob/master/src/main/resources/hudson/plugins/copyartifact/ParameterizedBuildSelector/help-parameterName.html

          ikedam added a comment - Pass the parameter value, not the parameter name, like: selector: buildParameter(params.UPSTREAM) Please also see the help of parameterName: https://github.com/jenkinsci/copyartifact-plugin/blob/master/src/main/resources/hudson/plugins/copyartifact/ParameterizedBuildSelector/help-parameterName.html
          ikedam made changes -
          Assignee New: Ryan Desmond [ rdesmond ]
          Resolution New: Won't Fix [ 2 ]
          Status Original: Open [ 1 ] New: Fixed but Unreleased [ 10203 ]

          Ryan Desmond added a comment - - edited

          Thank you for looking into this and noting that!

          I did find this to be a weird gotcha, since the documentation suggests that the other way would work (and outside of the first run – it does).  Might you consider noting this gotcha in the help and/or readme?  The documentation suggests that it these items are interchangeable, and  with the recent development on  pipelines, I would think more people will hit this.

          For instance, in the help: 

          A "build selector" parameter's name or value.  A special parameter type exists
          which presents the user with selector options.
          
          If using the name, it must match the parameter name in the properties.
          
          In a pipeline and with the workflow-plugin you can use the parameter value itself.
          This is necessary in pipelines with dynamically created parameters, in which
          the defaults are not available during the first run when using the parameter's name.

          And then in the wiki at https://wiki.jenkins.io/display/JENKINS/Copy+Artifact+Plugin#CopyArtifactPlugin-Pipelinesyntax

          buildParameter Specified by a build parameter value (such as params.VALUE)
          lastCompleted completed build (ignoring build status)
          lastSuccessful Latest successful build
          latestSavedBuild Latest saved build (marked "keep forever")
          permalink Specified by permalink
          specific Specific build
          upstream Upstream build that triggered this job

           

          Ryan Desmond added a comment - - edited Thank you for looking into this and noting that! I did find this to be a weird gotcha, since the documentation suggests that the other way would work (and outside of the first run – it does).  Might you consider noting this gotcha in the help and/or readme?  The documentation suggests that it these items are interchangeable, and  with the recent development on  pipelines, I would think more people will hit this. For instance, in the help:  A "build selector" parameter's name or value. A special parameter type exists which presents the user with selector options. If using the name, it must match the parameter name in the properties. In a pipeline and with the workflow-plugin you can use the parameter value itself. This is necessary in pipelines with dynamically created parameters, in which the defaults are not available during the first run when using the parameter's name. And then in the wiki at https://wiki.jenkins.io/display/JENKINS/Copy+Artifact+Plugin#CopyArtifactPlugin-Pipelinesyntax buildParameter Specified by a build parameter value (such as params.VALUE) lastCompleted completed build (ignoring build status) lastSuccessful Latest successful build latestSavedBuild Latest saved build (marked "keep forever") permalink Specified by permalink specific Specific build upstream Upstream build that triggered this job  

            rdesmond Ryan Desmond
            rdesmond Ryan Desmond
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: