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

Delete workspace before build starts ignores Exlude patterns (for directories)

    XMLWordPrintable

Details

    • Bug
    • Status: Open (View Workflow)
    • Critical
    • Resolution: Unresolved
    • ws-cleanup-plugin

    Description

      I need to exclude some directories from being deleted on workspace cleanup. It always deleted the entire workspace, pattern is always ignored.
      I used several combinations: */DIRNAME/., DIRNAME/., DIRNAME, *DIRNAME with or without checking "Apply pattern also on directories"

      Attachments

        Issue Links

          Activity

            grim Grim Reaper added a comment - - edited

            Jenkins Versions: 2.60.3 & 2.73.3 (WAR deployments on WildFly)
            Plugin Version: 0.34
            Platform: Linux
            Plugins:
            Git client plugin 2.6.0
            Git plugin 3.6.4

            Details:
            No issues when the SCM is CVS. However we are migrating from CVS to GIT.
            When I configure a freestyle job to use GIT as the SCM and with "Delete workspace before build starts" checked it ignores any "Advanced" options I use (I'm trying to exclude ' *.build.* ' and a 'reports/**' directory) and just deletes everything in the entire workspace.

            In troubleshooting I also testing the Post Build Action > "Delete workspace when build is done". This half works. I can tell it to "Exclude" specific files, but as soon as the "Apply pattern also on directories" is checked it goes back to the above behavior of deleting everything regardless of excludes.

            Really hoping someone can have a look at this and find the root cause and a fix.

            Thanks in advance!

            Edit:
            I forgot to add that the GIT install is on a windows machine and the repo is located through a UNC share. Not that I think this has any bearing as the repo pull/clone works fine. Just trying to provide as much info as possible.

            grim Grim Reaper added a comment - - edited Jenkins Versions: 2.60.3 & 2.73.3 (WAR deployments on WildFly) Plugin Version: 0.34 Platform: Linux Plugins: Git client plugin 2.6.0 Git plugin 3.6.4 Details: No issues when the SCM is CVS. However we are migrating from CVS to GIT. When I configure a freestyle job to use GIT as the SCM and with "Delete workspace before build starts" checked it ignores any "Advanced" options I use (I'm trying to exclude ' * .build. * ' and a 'reports/**' directory) and just deletes everything in the entire workspace. In troubleshooting I also testing the Post Build Action > "Delete workspace when build is done". This half works. I can tell it to "Exclude" specific files, but as soon as the "Apply pattern also on directories" is checked it goes back to the above behavior of deleting everything regardless of excludes. Really hoping someone can have a look at this and find the root cause and a fix. Thanks in advance! Edit: I forgot to add that the GIT install is on a windows machine and the repo is located through a UNC share. Not that I think this has any bearing as the repo pull/clone works fine. Just trying to provide as much info as possible.
            grim Grim Reaper added a comment -

            Assigning to you as the plugins page indicates you are the ws-cleanup maintainer.
            Also for visibility.

            grim Grim Reaper added a comment - Assigning to you as the plugins page indicates you are the ws-cleanup maintainer. Also for visibility.
            grim Grim Reaper added a comment -

            For those looking for a work around, I've use the following plugin:
            https://plugins.jenkins.io/preSCMbuildstep

            With the following Shell script to do the same thing as WS-cleanup.

            echo "Deleting..."
            ls ${WORKSPACE}/ | egrep -v '*.build.*|suppressions.xml|reports' 
            ls ${WORKSPACE}/ | egrep -v '*.build.*|suppressions.xml|reports' | xargs rm -rf
            

             

            The above deletes everything except the items in the "egrep" command (excludes).

            grim Grim Reaper added a comment - For those looking for a work around, I've use the following plugin: https://plugins.jenkins.io/preSCMbuildstep With the following Shell script to do the same thing as WS-cleanup. echo "Deleting..." ls ${WORKSPACE}/ | egrep -v '*.build.*|suppressions.xml|reports' ls ${WORKSPACE}/ | egrep -v '*.build.*|suppressions.xml|reports' | xargs rm -rf   The above deletes everything except the items in the "egrep" command (excludes).
            tpbradt Tim Bradt added a comment -

            This bug is unfortunate.  We're trying to preserve our IntelliJ project files so we don't have to restore project settings every time we build.  This should really be addressed.

            +1 vote

            tpbradt Tim Bradt added a comment - This bug is unfortunate.  We're trying to preserve our IntelliJ project files so we don't have to restore project settings every time we build.  This should really be addressed. +1 vote
            grim Grim Reaper added a comment - - edited

            Updated my test server to Jenkins 2.89.4 and we are now using "Gitea" as our backend SCM.

            Still the same issue.

            Also update on the work around. Found out it wasn't working as intended. So now I shuffle files around to make it work. This is all on Linux.

            Steps to configure the job:

            1. Under "Source Code management" (Git), select "Wipe out repo & force clone" under "Additional behaviours".
            2. Under "Build Environment", note you still need to have the preSCMBuildStep plugin and check "Run buildstep before SCM runs" and add "Execute shell", then use the following to "Exclude files" (You may need to modify for your needs):
              # Move build files to temp location before workspace wipe
              ls -Al "${WORKSPACE}"
              [ ! -d "/tmp/${BUILD_TAG}/" ] && mkdir -p "/tmp/${BUILD_TAG}/"
              mv -v "${WORKSPACE}"/*.build.* "${WORKSPACE}"/suppressions.xml "/tmp/${BUILD_TAG}/"
              ls -Al "/tmp/${BUILD_TAG}/"
              
            1. Under the "Build" section of your job. Add "Execute shell" and move it to the top. In the textbox add the following script commands to move your files back into the workspace:
              # Move build files back to workspace before build runs 
              mv -v "/tmp/${BUILD_TAG}"/* "${WORKSPACE}" 
              ls -Al "${WORKSPACE}" 
              rm -rfv "/tmp/${BUILD_TAG}/"
              

            Off to try the latest and greatest Jenkins (Hopefully it can still build our legacy apps >.<).

             

            grim Grim Reaper added a comment - - edited Updated my test server to Jenkins 2.89.4 and we are now using "Gitea" as our backend SCM. Still the same issue. Also update on the work around. Found out it wasn't working as intended. So now I shuffle files around to make it work. This is all on Linux. Steps to configure the job: Under "Source Code management" (Git), select "Wipe out repo & force clone" under "Additional behaviours". Under "Build Environment", note you still need to have the preSCMBuildStep plugin and check "Run buildstep before SCM runs" and add "Execute shell", then use the following to "Exclude files" (You may need to modify for your needs): # Move build files to temp location before workspace wipe ls -Al "${WORKSPACE}" [ ! -d "/tmp/${BUILD_TAG}/" ] && mkdir -p "/tmp/${BUILD_TAG}/" mv -v "${WORKSPACE}" /*.build.* "${WORKSPACE}" /suppressions.xml "/tmp/${BUILD_TAG}/" ls -Al "/tmp/${BUILD_TAG}/" Under the "Build" section of your job. Add "Execute shell" and move it to the top. In the textbox add the following script commands to move your files back into the workspace: # Move build files back to workspace before build runs mv -v "/tmp/${BUILD_TAG}" /* "${WORKSPACE}" ls -Al "${WORKSPACE}" rm -rfv "/tmp/${BUILD_TAG}/" Off to try the latest and greatest Jenkins (Hopefully it can still build our legacy apps >.<).  

            People

              olivergondza Oliver Gondža
              bavoiculescu Voiculescu Bogdan Alexandru
              Votes:
              8 Vote for this issue
              Watchers:
              12 Start watching this issue

              Dates

                Created:
                Updated: