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

Add ability to perform actions on branch removal

      This is similar request to https://issues.jenkins-ci.org/browse/JENKINS-37907, but for workflow-multibranch-plugin.

      Rationale:
      Team is using short term feature branches and for each of them SonarQube analysis is executed. SonarQube treats branch builds as separate SonarQube projects. I would like to have a possibility to hook in when branch is being deleted and call SonarQube API to delete this branch-specific project.

          [JENKINS-40606] Add ability to perform actions on branch removal

          Grzegorz Poznachowski created issue -
          Jesse Glick made changes -
          Link New: This issue relates to JENKINS-37907 [ JENKINS-37907 ]

          Jesse Glick added a comment -

          Use ItemListener.onDeleted from a plugin. I suppose you are asking for some sort of “userspace” hook, like a shell script or something, which you could configure perhaps as a JobProperty. If so, this would better be moved to plugin-proposals.

          Seems like a straight-up duplicate of JENKINS-37907, which seems to have been closed improperly.

          Jesse Glick added a comment - Use ItemListener.onDeleted from a plugin. I suppose you are asking for some sort of “userspace” hook, like a shell script or something, which you could configure perhaps as a JobProperty . If so, this would better be moved to plugin-proposals . Seems like a straight-up duplicate of JENKINS-37907 , which seems to have been closed improperly.

          Grzegorz Poznachowski added a comment - - edited

          I assume that would require writing a separate Jenkins plugin for that (like here)? Or, could I use it in Jenkinsfile? And yes, I was asking if there is any posibility to achieve that (i.e. via script) beside coding a dedicated plugin.

          Grzegorz Poznachowski added a comment - - edited I assume that would require writing a separate Jenkins plugin for that (like here )? Or, could I use it in Jenkinsfile? And yes, I was asking if there is any posibility to achieve that (i.e. via script) beside coding a dedicated plugin.

          Jesse Glick added a comment -

          could I use it in Jenkinsfile?

          No, because this is outside a build context.

          Jesse Glick added a comment - could I use it in Jenkinsfile? No, because this is outside a build context.
          Jesse Glick made changes -
          Component/s New: plugin-proposals [ 15491 ]
          Component/s Original: workflow-multibranch-plugin [ 21465 ]
          Labels New: multibranch

          Is something changed in the context of this ticket with 2.x plugins available?

          Grzegorz Poznachowski added a comment - Is something changed in the context of this ticket with 2.x plugins available?

          Jesse Glick added a comment -

          Not that I am aware of.

          Jesse Glick added a comment - Not that I am aware of.

          Jacobus Geluk added a comment -

          Ideally, you would want to be able to run a special section in your Jenkinsfile that gets executed just before a job and its workspace gets deleted (only when it actually has one). Even though at that point the git-branch is already deleted and a fetch for the latest version would be impossible, it would allow cleanup scripts that still reside in the workspace from its last execution to be executed.

          Jacobus Geluk added a comment - Ideally, you would want to be able to run a special section in your Jenkinsfile that gets executed just before a job and its workspace gets deleted (only when it actually has one). Even though at that point the git-branch is already deleted and a fetch for the latest version would be impossible, it would allow cleanup scripts that still reside in the workspace from its last execution to be executed.

          jgeluk ah but where would you log that execution? How would you find out that it failed?

          I think this could be more easily handled by an extension plugin.

          You have the listener, a multibranch project property could add an action that shows the tidy-up logs and you could have some pipeline step that defines the tidy-up steps of a branch in the pipeline. Then the listener looks at the branch, sees that it has the tidy-up steps action, grabs them and allows the delete to continue...meanwhile it schedules an execution of the tidy-up that is attached to the multibranch project rather than the job.

          Now the above is not trivial... but it is all straighforward (i.e. I do not envision any major pitfalls along the way) and I think it would fit into the overall design for how all these things work quite well

          Stephen Connolly added a comment - jgeluk ah but where would you log that execution? How would you find out that it failed? I think this could be more easily handled by an extension plugin. You have the listener, a multibranch project property could add an action that shows the tidy-up logs and you could have some pipeline step that defines the tidy-up steps of a branch in the pipeline. Then the listener looks at the branch, sees that it has the tidy-up steps action, grabs them and allows the delete to continue...meanwhile it schedules an execution of the tidy-up that is attached to the multibranch project rather than the job. Now the above is not trivial... but it is all straighforward (i.e. I do not envision any major pitfalls along the way) and I think it would fit into the overall design for how all these things work quite well

            Unassigned Unassigned
            dziesio Grzegorz Poznachowski
            Votes:
            21 Vote for this issue
            Watchers:
            27 Start watching this issue

              Created:
              Updated: