Search code examples
jenkinsarchive

How to keep folder structure when archiving files in Jenkins?


The Jenkins version running is 2.249.1. I am new to Jenkins, so I may be missing something very obvious here. I found a few related stack overflow questions, but nothing answered this question specifically. I found this question to be helpful but still didn't answer the question being asked.

This is all being done through the Jenkins GUI. I added a post build action to archive files. Here is the screen screen that I am seeing.

I am trying to archive all the files while keeping their folder structure. I am able to add all the files while losing their folder structure with this pattern: **/*.*

Using a single * only grabs the outermost README.md and ignores all the folders beneath the working directory. I realize I can list each directory specifically to accomplish this, but it seems like there should be a simple way to grab everything and keep the folder structure.

Thanks!


Solution

  • Per the 'Files to archive [ ]' help icon (?) ,

    You can use wildcards like 'module/dist/**/*.zip'.See the includes attribute of Ant fileset for the exact format.

    Suggest reading the ant fileset documentation carefully.

    Files to archive [ **/** ]
    

    will copy the the entire directory structure and folders. The **/ matches all directories and the /** matches all contents. If the contents is a directory, process as a directory, if it's a file, copy it.

    Something like myrootdir/**/matchingdir*/** could produce:

    myrootdir/user/matchingdirWeb/logging-log4j2-web.xml
    myrootdir/user/matchingdirWeb/logging-web.xml
    myrootdir/user/matchingdirWS/logging-log4j2-service.xml
    myrootdir/user/matchingdirWS/logging-service.xml
    myrootdir/Web/matchingdirWeb/logging-log4j2-web.xml
    myrootdir/Web/matchingdirWeb/logging-web.xml
    myrootdir/WS/matchingdirWS/logging-log4j2-service
    myrootdir/WS/matchingdirWS/logging-log4j2-service.xml
    myrootdir/WS/matchingdirWS/logging-service.xml
    

    You must actually click on the "Build Artifacts" (open box) button to navigate into "<build>/artifact" to see the tree. The main build page may not show the complete path to the files.

    You should also set a smart retention policy [ X ] Discard old builds if you don't want to blow up your disk consumption. See this answer for more details.