fix(delete): [JENKINS-70252] delete WorkflowRun before WorkflowJob - #463
fix(delete): [JENKINS-70252] delete WorkflowRun before WorkflowJob#463a1k0u wants to merge 1 commit into
Conversation
| setDisabled(true); | ||
| Jenkins.get().getQueue().cancel(this); | ||
|
|
||
| for (WorkflowRun workflowRun : getBuilds()) { |
There was a problem hiding this comment.
The trouble is that this will make performance worse for those not using artifact-manager-s3 (or those using it in its default and only supported mode, which never deletes artifacts), since loading potentially thousands of WorkflowRun objects from so many little XML files is expensive. Anyway deleting those S3 directories one by one would be inefficient.
Fixing this properly would have to take a different approach I think. https://javadoc.jenkins.io/jenkins/model/ArtifactManager.html#delete() cannot handle this since the whole object is scoped per build. https://javadoc.jenkins.io/jenkins/model/ArtifactManagerFactory.html could have a delete(Job) method, perhaps. Or JCloudsArtifactManager (or something else in the plugin) could check ItemListener.onDeleted and delete the whole directory with one API call.
We use the repository scanning feature in the cloudbees-folder-plugin with Multi Branch Pipeline project to delete non-existent branches. When the folder plugin finds out which branch should be deleted, it calls the delete method in the
Iclass (AbstractFolder<I>), in our case it is WorkflowJob. WorkflowJob only overrides theperformDeletemethod, where it disables the job, exits the queue and callsAbstractItem.performDelete(). This way WorkflowJob only recursively deletes files under it. There is no logic for deleting artifacts under a WorkflowRun. This is why, for example, artifacts are not deleted from S3 after deleting a branch (second case in the linked issue).But if you delete only the WorkflowRun (for example
logRotatorin pipeline options), it will delete artifacts because the parent class callsdeleteArtifactsin thedeletemethod (fisrt case in the linked issue).I believe it would be correct to update
hudson.model.Job, where to add logic to remove builds (hudson.model.Run) fromgetBuilds. But it was much easier to make changes to the plugin and test it in a production environment.Testing done
I really don't know how to test this properly. I just made the changes and tested it in our Jenkins instance. Everything is working as I expected. I will be glad to know how to test this fix.
Submitter checklist
https://issues.jenkins.io/browse/JENKINS-70252