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

ability to specify a path prefix to archiveArtifacts


    • Icon: Improvement Improvement
    • Resolution: Unresolved
    • Icon: Minor Minor
    • core
    • None
    • jenkins core 2.89.1 (LTS)
      workflow-basic-steps 2.6

      When attempting to archive files with duplicate relative basename / filename between multiple parallel branches, the file version captured by the latest (wallclock) invocation of archiveArtifacts is the only version that is archived. Working around this either requires unique dir/workspace construction per branch or manually copying files into a new relative path hierarchy that is the only path tree archived (per branch).

      I have been using both techniques and neither is very convient. Using unique dir()/ws() to solve this problem is unsatisfactory in term of pipeline fragment reuse via utlity methods. As this construct:

      dir('foo') {
        util.runCommonOperation() // archives stuff

      is unable to capture the top level foo directory as part of the artifact(s) path. This requires either decomposing runCommonOperation() so that it doesn't call the archiveArtifact step or passing down a path parameter. The former is undesirable as some of my jobs have a dozen lines or more of logic around what to archive and it requires lifting up error handling logic. The later results in having to add path parameters to many utility methods.

      Manually copying files around to construct the desired archive path(s) is awkward in that it requires invoking shell steps (the pipeline dsl doesn't have good facilities for working with files and using jenkins file related methods requires opening holes in the groovy sandbox) and an extra house keeping step is required to make sure the "archive" file dir is cleaned up between builds (trivial but I have forgotten to do this).

      I think that simply adding a prefix or artifact name mangling regexp parameter to the archiveArtifacts step would be useful both for solving the parallel branch use-case and in general, even for serial builds.

      Another option would be to add automatic parallel branch detection and to append the branch name as a top level dir. This has merit in that it would prevent the unaware user from stumbling upon this problem. Yet another option would be for the archiveArtifacts step to generate warnings (by default but with a disable flag) when attempting to archive duplicate file path/names.

            Unassigned Unassigned
            jhoblitt Joshua Hoblitt
            9 Vote for this issue
            12 Start watching this issue