jenkinsci / plasticscm-plugin

A plugin for Jenkins to be able to use Plastic SCM
MIT License
15 stars 31 forks source link

Cleanup Method ignored for Multi-Configuration projects #50

Closed mikeseese closed 1 year ago

mikeseese commented 2 years ago

Jenkins and plugins versions report

Environment ```text Jenkins: 2.332.3 OS: Linux - 5.4.0-100-generic --- ace-editor:1.1 ant:475.vf34069fef73c antisamy-markup-formatter:2.7 apache-httpcomponents-client-4-api:4.5.13-1.0 bootstrap5-api:5.1.3-6 bouncycastle-api:2.26 branch-api:2.1046.v0ca_37783ecc5 build-timeout:1.20 caffeine-api:2.9.3-65.v6a_47d0f4d1fe checks-api:1.7.4 cloudbees-folder:6.714.v79e858ef76a_2 command-launcher:81.v9c2cb_cb_db_392 credentials:1087.1089.v2f1b_9a_b_040e4 credentials-binding:523.vd859a_4b_122e6 display-url-api:2.3.6 durable-task:496.va67c6f9eefa7 echarts-api:5.3.2-1 email-ext:2.88 font-awesome-api:6.0.0-1 git:4.11.1 git-client:3.11.0 git-server:1.11 github:1.34.3 github-api:1.303-400.v35c2d8258028 github-branch-source:1628.vb_2f51293cb_78 gradle:1.38 handlebars:3.0.8 jackson2-api:2.13.2.20220328-273.v11d70a_b_a_1a_52 javax-activation-api:1.2.0-3 javax-mail-api:1.6.2-6 jaxb:2.3.6-1 jdk-tool:1.5 jjwt-api:0.11.2-71.v2722b_b_06a_2a_f jquery3-api:3.6.0-3 jsch:0.1.55.2 junit:1.63 ldap:2.9 lockable-resources:2.15 mailer:414.vcc4c33714601 matrix-auth:3.1.2 matrix-project:771.v574584b_39e60 momentjs:1.1.1 okhttp-api:4.9.3-105.vb96869f8ac3a p4:1.12.3 pam-auth:1.8 pipeline-build-step:2.18 pipeline-github-lib:36.v4c01db_ca_ed16 pipeline-graph-analysis:195.v5812d95a_a_2f9 pipeline-input-step:448.v37cea_9a_10a_70 pipeline-milestone-step:101.vd572fef9d926 pipeline-model-api:2.2077.vc78ec45162f1 pipeline-model-definition:2.2077.vc78ec45162f1 pipeline-model-extensions:2.2077.vc78ec45162f1 pipeline-rest-api:2.24 pipeline-stage-step:293.v200037eefcd5 pipeline-stage-tags-metadata:2.2077.vc78ec45162f1 pipeline-stage-view:2.24 plain-credentials:1.8 plasticscm-plugin:4.0 plugin-util-api:2.16.0 popper2-api:2.11.5-1 resource-disposer:0.19 scm-api:608.vfa_f971c5a_a_e9 script-security:1158.v7c1b_73a_69a_08 snakeyaml-api:1.30.1 ssh-credentials:277.v95c2fec1c047 ssh-slaves:1.814.vc82988f54b_10 sshd:3.228.v4c9f9e652c86 structs:318.va_f3ccb_729b_71 timestamper:1.17 token-macro:293.v283932a_0a_b_49 trilead-api:1.57.v6e90e07157e1 variant:1.4 workflow-aggregator:2.7 workflow-api:1144.v61c3180fa_03f workflow-basic-steps:948.v2c72a_091b_b_68 workflow-cps:2689.v434009a_31b_f1 workflow-cps-global-lib:575.v24fa_0a_b_f7383 workflow-durable-task-step:1130.v8fd69d0b_8857 workflow-job:1180.v04c4e75dce43 workflow-multibranch:712.vc169a_1387405 workflow-scm-step:400.v6b_89a_1317c9a_ workflow-step-api:625.vd896b_f445a_f8 workflow-support:819.v37d707a_71d9b_ ws-cleanup:0.42 ```

What Operating System are you using (both controller, and any agents involved in the problem)?

Controller: Ubuntu 20.04 1 Agent: Windows 11 Pro 22H2 (Build 22610.1)

Reproduction steps

  1. Create Multi-Configuration Project
  2. Select Minimal or Standard Cleanup Method
  3. Under the configuration matrix select a single node/agent
  4. Build once
  5. Build again
  6. Observe the logs of both builds

Expected Results

It should not delete the repository during the second build since the Cleanup Method doesn't specify to delete the repository.

Actual Results

Near the top of the full build logs you'll notice it deleting the repository before recreating it:

00:00:00.298 [Project] $ cm workspace list --format={wkname}#{path}#{wkid} -wks=Org@cloud
00:00:01.003 jenkins_5317139074a84deeafd45ef86319c0d4#d:\jenkins\workspace\Project\nodes\Incredibuild#***
00:00:01.153 [Project}] $ cm workspace delete d:\jenkins\workspace\Rocklen\nodes\Incredibuild -wks=Org@cloud
00:00:01.861 The workspace jenkins_5317139074a84deeafd45ef86319c0d4 has been deleted.
00:00:02.390 [Project] $ cm workspace create jenkins_725444647b5e45f5ad07fe30d94dd320 D:\jenkins\workspace\Project --selector=D:\jenkins\workspace\Project\selector5507399919618997130.txt -wks=Org@cloud

Anything else?

I believe this is happening due to the lines here: https://github.com/jenkinsci/plasticscm-plugin/blob/HEAD/src/main/java/com/codicesoftware/plugins/hudson/actions/CheckoutAction.java#L81-L84

It's possible the function should be something like:

    private static void deleteOldWorkspacesIfNeeded(
            PlasticTool tool,
            FilePath workspacePath,
            CleanupMethod cleanup,
            List<Workspace> workspaces)
            throws IOException, InterruptedException {

        if (cleanup == CleanupMethod.DELETE) {
            // Handle situation where workspace exists in child path.
            List<Workspace> innerWorkspaces = findWorkspacesInsidePath(workspacePath, workspaces);
            for (Workspace workspace : innerWorkspaces) {
                deleteWorkspace(tool, workspace, workspaces);
            }

              // Handle situation where workspace exists in parent path.
            List<Workspace> outerWorkspaces = findWorkspacesOutsidePath(workspacePath, workspaces);
            for (Workspace workspace : outerWorkspaces) {
                deleteWorkspace(tool, workspace, workspaces);
            }

            Workspace workspace = findWorkspaceByPath(workspacePath, workspaces);
            if (workspace != null) {
                deleteWorkspace(tool, workspace, workspaces);
            }
        }
    }
mig42 commented 2 years ago

Thanks for the report! I added it to our backlog.

pablegarcia commented 1 year ago

Hi @mikeseese!! As I can see in your comment, when you reported this issue you were using the plugin version 4.0. Please, could you upgrade the plastic plugin to the latest version 4.4, and try to reproduce it again? We introduced some significant changes in version 4.3 related to how we're checking workspaces to delete, so we think it could be resolved. Moreover, we couldn't reproduce this issue with version 4.4. On the other hand, if this issue is still happening with version 4.4, would you be so kind as to create a new issue? Thanks in advance.