Perhaps you should be asking, “why do you have remnant artifacts for prior build runs in your workspace?”
You can use the Workspace Cleanup plugin ( pipeline step cleanWs() ) to clean the entire workspace, or specific directories or patterns. See the plugin docs for use cases.
It can also be applied prior to beginning a build.
Then you end up archiving only the latest artifacts since that’s all that’s in the workspace.
Best practice for both maven and ant is to have a clean target which removes either all build artifacts, or the intermediary artifacts.
I am using cleanWS() to clean the workspace, but I am not sure if it can be used to delete artifacts… I still have artifacts archived here (which is what I want).
Archived artifacts are stored on the controller; they are copied from the workspace on the node to the controller in a folder within the build log in an archive directory: ${JENKINS_HOME}/jobs/path/jobs/to/jobs/MYJOB/builds/##/archive
or each run as a post-build-step. You can access them from the UI’s specific build job log page:
(${JENKINS_JOB_URL}/##/artifacts).
Once archived, you can delete the workspace.
If you delete the build log, you will lose the artifacts, as well as if you delete the job itself.