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

Make the BuildNumber that artifacts were copied from available to later build steps.

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      When copying artifacts from another job, the build selector can be set to things like "Latest Stable Build".

      I have a couple of places where, having copied in artifact, I'd like to know which build number they came from.

      Admittedly this can be retrived by going to "http://YOURJENKINS/job/JOBNAME/X/buildNumber" where X is "lastBuild", "lastSuccessfulBuild", "lastStableBuild" and so on. However, there is a chance that this will return a different build number is the copy happened just before a build completed.

      I'd like to see this plugin store the build number used e.g. into an environment variable that can be then be access by later build step. The environment variable name would have to be configurable to cope with cases there a build combines artifacts from two different upstream builds.

        Attachments

          Activity

          Hide
          mindless Alan Harder added a comment -

          I'm not sure how to get this information to you.. this is a BuildStep, not a BuildWrapper, so I'm not aware of a way to modify the env vars.. if you can find some way via BuildStep.perform() API to tell you the build# I'd be happy to add this..

          Show
          mindless Alan Harder added a comment - I'm not sure how to get this information to you.. this is a BuildStep, not a BuildWrapper, so I'm not aware of a way to modify the env vars.. if you can find some way via BuildStep.perform() API to tell you the build# I'd be happy to add this..
          Hide
          mindless Alan Harder added a comment -

          I found a way:
          1) Plugin has a RunListener.. as each build starts, if that job has one or more CopyArtifact build steps then it adds an EnvironmentContributingAction to the build.
          2) As the CopyArtifact build steps run, it provides data to that action which can be used when later steps get the environment.

          Now, as to what exactly should go in the env..

          • Could be a fixed name like COPYARTIFACT_BUILD_NUMBER.. but this would only give the last value if you have multiple CopyArtifact build steps.
          • Could be a name based on the source project like COPYARTIFACT_BUILD_NUMBER_MYPROJNAME

          I'd prefer not to have another config option, so I'll probably do the second item above.. let me know if you have other ideas.

          Show
          mindless Alan Harder added a comment - I found a way: 1) Plugin has a RunListener.. as each build starts, if that job has one or more CopyArtifact build steps then it adds an EnvironmentContributingAction to the build. 2) As the CopyArtifact build steps run, it provides data to that action which can be used when later steps get the environment. Now, as to what exactly should go in the env.. Could be a fixed name like COPYARTIFACT_BUILD_NUMBER.. but this would only give the last value if you have multiple CopyArtifact build steps. Could be a name based on the source project like COPYARTIFACT_BUILD_NUMBER_MYPROJNAME I'd prefer not to have another config option, so I'll probably do the second item above.. let me know if you have other ideas.
          Hide
          grhm Graham Smith added a comment -

          Wow, this was not an urgent issue, yet I've gone away for a day and you've fixed it. Well Done.

          I'd assumed you'd put in a config option, but agree that's not ideal. Your suggestion above of COPYARTIFACT_BUILD_NUMBER_MYPROJNAME looks good and would probably be the best option.

          I look forward to using it when the next version of the plugin is released.
          Many Thanks

          Show
          grhm Graham Smith added a comment - Wow, this was not an urgent issue, yet I've gone away for a day and you've fixed it. Well Done. I'd assumed you'd put in a config option, but agree that's not ideal. Your suggestion above of COPYARTIFACT_BUILD_NUMBER_MYPROJNAME looks good and would probably be the best option. I look forward to using it when the next version of the plugin is released. Many Thanks
          Hide
          servel333 Nathan Perry added a comment -

          This bugfix just helped me out and is perfect with the project name in the environment variable name. Thanks.

          Show
          servel333 Nathan Perry added a comment - This bugfix just helped me out and is perfect with the project name in the environment variable name. Thanks.
          Hide
          chris_williams1 Chris Williams added a comment -

          This is a very useful variable but could you allow numbers in the project name to carry over to COPYARTIFACT_BUILD_NUMBER_ ? We have projects such as "FOO_MODE1_BUILD", and we lose the number: COPYARTIFACT_BUILD_NUMBER_FOO_MODE_BUILD

          Thanks!

          Show
          chris_williams1 Chris Williams added a comment - This is a very useful variable but could you allow numbers in the project name to carry over to COPYARTIFACT_BUILD_NUMBER_ ? We have projects such as "FOO_MODE1_BUILD", and we lose the number: COPYARTIFACT_BUILD_NUMBER_FOO_MODE_BUILD Thanks!
          Hide
          sdram111 Ramkumar D added a comment - - edited

          The Job Name needs to be converted to capital and hyphen needs to be converted to underscore to achieve this result. If we just append the job name to this COPYARTIFACT_BUILD_NUMBER_ then it will be nice. 

          Show
          sdram111 Ramkumar D added a comment - - edited The Job Name needs to be converted to capital and hyphen needs to be converted to underscore to achieve this result. If we just append the job name to this COPYARTIFACT_BUILD_NUMBER_ then it will be nice. 
          Hide
          christiankarsch Christian Karsch added a comment - - edited

          Is there a possibility to get the build number?

          I tried it with the variable COPYARTIFACT_BUILD_NUMBER_xxx, but I only get a MissingPropertyException exeption.

          Would it be much easier to supply the buildnumber as a return value:

          def number = copyArtifacts ...

          currently i get only a null-object as return value

          (Note: i used declarative pipeline scripts)

           

          EDIT: there exist a issure https://issues.jenkins-ci.org/browse/JENKINS-34620

          Show
          christiankarsch Christian Karsch added a comment - - edited Is there a possibility to get the build number? I tried it with the variable COPYARTIFACT_BUILD_NUMBER_xxx, but I only get a MissingPropertyException exeption. Would it be much easier to supply the buildnumber as a return value: def number = copyArtifacts ... currently i get only a null-object as return value (Note: i used declarative pipeline scripts)   EDIT: there exist a issure https://issues.jenkins-ci.org/browse/JENKINS-34620

            People

            • Assignee:
              mindless Alan Harder
              Reporter:
              grhm Graham Smith
            • Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: